Reputation: 25556
I am trying to change the value of this disabled input. I thought maybe the fact that it was disabled was the problem so I removed the disabled attribute manually (in case you were wondering why it is no longer disabled in the screenshot). See image below:
From what the console returns it seems to be selecting the input properly, but the value of the input remains blank, even when the input is enabled. What am I doing wrong?
Upvotes: 3
Views: 9935
Reputation: 25107
Not sure what the rest of the page looks like, but I can see that you're nesting tables - might lead to confusion and unexpected results, especially with hidden nested tables. Are you going to show the hidden table when the user clicks the add-btn
? If so, why not get the text button by looking for it in the click event, relative to the clicked button?
$(".add-btn").click(function(evt){
var product = getProductNameSomehow(); // Up to you
var newContainer = $(this).siblings("table").find(".new-row-html");
newContainer.find("input.product").val(product);
evt.preventDefault();
return false;
});
You could improve and generalize this example listener with $(...).on("click", ...)
. The .a-btn
would probably be better as a <button type="button">Add</button>
, perhaps styled as a link, if that's what you want, so you wouldn't have to worry about stopping the click event as much.
Upvotes: 0
Reputation: 554
I can tell you I have had simmilar issues, and have gotten arround them by using jQuery's attr method. It can set an arbitrary HTML attribute to whatever you want. See more here: http://api.jquery.com/attr/
Upvotes: 7