Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill a textbox with jQuery

Tags:

jquery

When I use this code, it doesn't want to work.

$('[id$=ADRESTextBox]').text(data[0]);

The data is an array as you can see. It really has a value (because I alerted it) How do you fill a certain textbox with jQuery.

like image 517
Thomas Avatar asked Feb 03 '11 17:02

Thomas


People also ask

How to set value in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.

How to set and get value in jQuery?

To get a form value with jQuery, you need to use the val() function. To set a form value with jQuery, you need to use the val() function, but to pass it a new value.


1 Answers

Set values of form elements with val():

$('[id$=ADRESTextBox]').val(data[0]);

If you are talking about text input elements: They don't have "content" anyway. It is a single, self-closing tag, so any attempt to put something inside the tag will fail. A text field's value is defined by its value attribute.

Update:

With respect to the comment: If ADRESTextBox is actually the full ID, use $('#ADRESTextBox') to select the element.

like image 53
Felix Kling Avatar answered Oct 01 '22 13:10

Felix Kling