tags:

views:

63

answers:

3

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]

+2  A: 

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
patrick dw
hello patrick, that doesn't work. the first line works without the .text
JP Hellemons
@JP Hellemons - The first line *was* the answer. I was just explaining why you needed to add `text()` to the end of your code.
patrick dw
sorry patrick, but i meant my own first line: ` $("#text11").append($(xml).find("address").find("street"));`that works without the .text() and i tested it with text() and didn't work, sorry
JP Hellemons
I see. What is the content of `street`? Perhaps you should post some of the XML markup. If `street` is indeed found, then `text()` should get its content. You could also test to see if `street` was found by checking its `length` property. I'll update my answer.
patrick dw
Thanks patrick for your time and effort. I have updated the question with the output of window.alert of the var street. the var street can be appended to the span though. strange that that does work...
JP Hellemons
You're getting [object Object] because `find()` will always return an object. You need to do `alert(street.length);` to see if the node was successfully located.
patrick dw
hello patrick, thanks for your update about the length somehow it showed 0. i have found it! i had this line:$("#text11").append($(xml).find("address").find("street"));and apparently you cannot retrieve it twice! so removing that line fixes it!
JP Hellemons
A: 

try..

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

or

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

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

Ilona