JP Hellemons
JP Hellemons

Reputation: 6057

set value of input

Sometimes code says more then words, so the following lines work:

 $("#text11").append($(xml).find("address").find("street"));
 $("#<%= tbWoonplaats.ClientID %>").val('testing?');

but these do not:

var street = $(xml).find("address").find("street");
$("#<%= tbAdres.ClientID %>").val(street);

it displays [object object] in the input now i've tried to replace .val(street); with .val(new string(street)); but that doesn't work either

appending to a span works but setting with .val() to input doesn't...

<span id="text11"></span>

EDIT the output of

var street = $(xml).find("address").find("street");
window.alert(street);

is: [object Object]

Upvotes: 6

Views: 29133

Answers (3)

Ilona
Ilona

Reputation: 9

$("#<%= tbAdres.ClientID %>").val(street.text());

Upvotes: -1

user113716
user113716

Reputation: 322592

Try this:

var street = $(xml).find("address").find("street").text();

You were getting the node with .find("street"), but not its content, so you needed .text().

http://api.jquery.com/text/


EDIT:

You can check to see if a street node was found using the length property.

var street = $(xml).find("address").find("street");

alert(street.length); // should alert at least 1 if the find was successful

Upvotes: 5

Reigel Gallarde
Reigel Gallarde

Reputation: 65284

try..

$("#<%= tbAdres.ClientID %>").val(street.html());

or

$("#<%= tbAdres.ClientID %>").val(street.text());

Upvotes: 0

Related Questions