This is my HTMLcode:
<div style='display:none;' id='allformid'>
<div>
<form action='#'>
<input type='text' name='name' id='named'/>
</form>
</div>
</div>
And this is my jQuery code to set the value of the input text box:
$("#allformid #named").val('abcd');
This jQuery code is correct, but the form value is not changed.
I tried the same code it works fine. How did you test that the code works or not?
If you check the inspect element, it will not show value="abcd". But if you make the div visible, you can see the value is given. But the value gets set. You can also test the value by getting the value in the js console like this:
$("#allformid #named").val();
However if you want it to display as value="abcd", you will need to write $("#allformid #named").attr("value",'abcd');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With