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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sharifsayyed
    New Member
    • Feb 2015
    • 1

    #1

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

    Code:
    <xml>
     <beneficiary>
      <District name="Nandurbar">
       <Taluka>Nandurbar</Taluka>
       <Taluka>Nawapur</Taluka>
       <Taluka>Akkalkuva</Taluka>
      </District>
      <District name="Dhule">
       <Taluka>Shirpur</Taluka>
       <Taluka>Shindkheda</Taluka>
       <Taluka>Sakri</Taluka>
      </District>
    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:


    Code:
    District name: <select id="district_name" onchange="loadXMLOption();">
    <opton value=""></option> 
    <option value="Nandurbar">Nandurbar</option>
    <option value="Dhule">Dhule</option> 
    <option value="Jalgaon">Jalgaon</option>
    </select>
    In the above code we are adding options manually instead of this it should fetch directly from XML
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    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.create Element() and node.appendChil d() methods for example.
    Last edited by gits; Feb 19 '15, 09:07 AM.

    Comment

    Working...