Reputation: 6810
I want to put a var text = "hello"
Into an input value. I am not sure how to do this, and I would like to know to this, as I am not sure.
I thought It would of just been $(input#text).text(text);
but that did not work
Upvotes: 1
Views: 5021
Reputation: 1785
you can use
var text = "hello"
$('#id').val(text);
//where id is the id assigned to your text box
//eg.
<input type='text' id='mytextbox' value=''/>
//it should be then
var text = "hello"
$('#mytextbox').val(text);
Upvotes: 1
Reputation: 10747
To assign value of a text box whose id is textbox in jQuery ,do the following :-
$("#textbox").val(text);
See val
Upvotes: 1
Reputation: 60997
If you look up the documentation of jQuery for text
, you'll see that text()
manipulates text nodes (or text node content). If you're setting a value on a textbox you should be using the val()
function.
$("input#text")
.val(text);
Upvotes: 2