By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Convert XML nodes to raw text

P: 65

I am trying to make a dynamic AJAX form in a webpage and I want to dynamically change a <select> box's options.

So I have a server-side PHP script which generates following response :

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <WebResponse>
  3. <WebResponseInd id="0">
  4. <Response>
  5. <Result>
  6.   <option value="1">First option</option>
  7.   <option value="2">Second option</option>
  8. </Result>
  9. </Response>
  10. </WebResponseInd>
  11. </WebResponse>
I want to insert options that lay within the <Result> tag directly into the webpage using document.getElementById("mySelect").innerHTML.

The problem is that getElementsByTagName('Result').item(0).nodeValue returns an empty string.

Is there any way to convert the node to text or string ?

Jul 23 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 5,343
what about:

Expand|Select|Wrap|Line Numbers
  1. getElementsByTagName('Result').innerHTML
?? :)

kind regards
Jul 23 '08 #2

rnd me
Expert 100+
P: 427
you generally can/should not use .innerHTML to build options.

build them manually, in a loop, and add each one separately.
Jul 24 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.