Reputation: 32490
I have a
<input type='text' id='text' value='' />
How do I programmatically set the value attrribute using JQuery/Javascript
Upvotes: 31
Views: 67454
Reputation: 8772
In jQuery, you'd do it like this:
$("#text").val("my new value");
You might also want to read the jQuery documentation on this topic
Without jQuery:
document.getElementById("text").setAttribute("value", "my new value");
Hope that helps.
Upvotes: 9
Reputation: 342635
The Javascript would be:
document.getElementById('text').value = 'Blahblah';
Upvotes: 13
Reputation: 12509
It's as easy as this:
$("#text").attr("value", "some value");
Upvotes: 22