8

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.

calvinf
  • 3,754
  • 3
  • 28
  • 41
Thomas
  • 297
  • 1
  • 8
  • 21

1 Answers1

11

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.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • 2
    Also using the pound selector for IDs '#ADRESTextBox' is a bit more standard. – Spencer Ruport Feb 03 '11 at 17:44
  • 2
    @Spencer Ruport: If the full ID is `ADRESTextBox`, then yes of course. But the code uses the *ends with* selector, so it might be that several input boxes are selected. – Felix Kling Feb 03 '11 at 17:46
  • A note, the poster may be using the selector syntax [name$=] to select multiple textareas at once, so the changes are made together. So they are not synonymous, although that could be what the poster needs (can't tell without more info). – Jared Farrish Feb 03 '11 at 17:49
  • Oh my mistake! I didn't realize that was an ends-with selector. – Spencer Ruport Feb 03 '11 at 19:22