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

How to fetch data from xml into combobox using javascript/php without using hardcoded

P: 1
Expand|Select|Wrap|Line Numbers
  1. <xml>
  2.  <beneficiary>
  3.   <District name="Nandurbar">
  4.    <Taluka>Nandurbar</Taluka>
  5.    <Taluka>Nawapur</Taluka>
  6.    <Taluka>Akkalkuva</Taluka>
  7.   </District>
  8.   <District name="Dhule">
  9.    <Taluka>Shirpur</Taluka>
  10.    <Taluka>Shindkheda</Taluka>
  11.    <Taluka>Sakri</Taluka>
  12.   </District>
  13.  
I want to retrieve the above xml data in combobox using javascript without using hardcoded data. I have searched many code examples but all are with hardcoded data only.

"hardcode" means we are manually adding options to combo box
Example of hardcoded options:


Expand|Select|Wrap|Line Numbers
  1. District name: <select id="district_name" onchange="loadXMLOption();">
  2. <opton value=""></option> 
  3. <option value="Nandurbar">Nandurbar</option>
  4. <option value="Dhule">Dhule</option> 
  5. <option value="Jalgaon">Jalgaon</option>
  6. </select>
  7.  
In the above code we are adding options manually instead of this it should fetch directly from XML
Feb 17 '15 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,317
you might use an XMLHttpRequest to retrieve the data (xml) and then parse it (example here) and add the options by utilizing the javascript DOM methods like document.createElement() and node.appendChild() methods for example.
Feb 19 '15 #2

Post your reply

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