1

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

4 Answers 4

2

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); 
Sign up to request clarification or add additional context in comments.

Comments

1

Use val() not text():

$("#text").val(text);

The val() is used when you want to read from or write to text fields.

Comments

1

To assign value of a text box whose id is textbox in jQuery ,do the following :-

$("#textbox").val(text);

See val

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.