473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

display the value from xml file when user click the drop down menu

Hi sir,

I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all city values should display in city selection field and when user select any one city value then this state of this city should be display auto in state
selection field without user selection. please solve my prolem.

Thank you.
Jul 19 '08 #1
6 4743
acoder
16,027 Expert Mod 8TB
What have you managed so far? This is the classical dependent drop-down problem. Post your code.
Jul 19 '08 #2
Hi Sir,
I'm new in XML , I 'm displaying the cities values in drop-down menu box from cities.xml file for city: field, through smarty and php code , on html form and I have next field is State which is also drop-down menu list box. I want when i select city name from city drop-down then state name of this city will become automatic in state drop-down menu box. currently i'm using saparate xml file for city and state. both xml file are below:

file: cities.xml
Expand|Select|Wrap|Line Numbers
  1. <cities>
  2.     <city><![CDATA[Abohar]]></city>
  3.     <city><![CDATA[Abu Road]]></city>
  4.     <city><![CDATA[Adilabad]]></city>
  5.     <city><![CDATA[Ariyalur]]></city>
  6.     <city><![CDATA[Agartala]]></city>
  7.     <city><![CDATA[Agra]]></city>
  8.     <city><![CDATA[Ahmedabad]]></city>
  9.     <city><![CDATA[Ahmednagar]]></city>
  10.     <city><![CDATA[Aizwal]]></city>
  11.     <city><![CDATA[Ajmer]]></city>
  12.     <city><![CDATA[Ajjampura]]></city>
  13.     <city><![CDATA[Akola]]></city>
  14.     <city><![CDATA[Aligarh]]></city>
  15. </cities>
[php]

function getCities() {
$filename = "cities.xml";
if (file_exists($filename)) {
$cities_obj = simplexml_load_file($filename);
$cities = $cities_obj->xpath('/cities/city');
return $cities;
} else {
echo "File does not exist";
}
}
$cities = getCities();
$main_smarty->assign("cities", $cities);[/php]


file: states.xml
Expand|Select|Wrap|Line Numbers
  1.  
  2. <states>
  3.     <state><![CDATA[Andaman and Nicobar Islands]]></state>
  4.     <state><![CDATA[Andhra Pradesh]]></state>
  5.     <state><![CDATA[Arunachal Pradesh]]></state>
  6.     <state><![CDATA[Assam]]></state>
  7.     <state><![CDATA[Bihar]]></state>
  8.     <state><![CDATA[Chandigarh]]></state>
  9.     <state><![CDATA[Chhattisgarh]]></state>
  10.     <state><![CDATA[Dadra and Nagar Haveli]]></state>
  11.     <state><![CDATA[Daman and Diu]]></state>
  12.     <state><![CDATA[Delhi]]></state>
  13.     <state><![CDATA[Goa]]></state>
  14.     <state><![CDATA[Gujarat]]></state>
  15.     <state><![CDATA[Haryana]]></state>
  16.     <state><![CDATA[Himachal Pradesh]]></state>
  17.     <state><![CDATA[Jammu and Kashmir]]></state>
  18.     <state><![CDATA[Jharkhand]]></state>
  19.     <state><![CDATA[Karnataka]]></state>
  20.     <state><![CDATA[Kerala]]></state>
  21. </states>
Php:
Expand|Select|Wrap|Line Numbers
  1.  
  2. function getStates(){
  3.     $filename="states.xml";
  4.     if (file_exists($filename)) {
  5.         $states_obj = simplexml_load_file($filename);
  6.         $states = $states_obj->xpath('/states/state');
  7.         return $states;
  8.     } else {
  9.         echo "File does not exist";
  10.     }
  11. }
  12. $states = getStates();    
  13. $main_smarty->assign("states", $states);

[HTML]

<tr>
<td align="right"><label for="cons_indi_prof_city">City<span class="req">*</span></label></td>
<td align="left">
<select name="cons_indi_prof_city" id="cons_indi_prof_city" style="width:180px" onChange="display(this,'ot');">
<option value="Select" selected="selected">Select</option>
{html_options values=$cities output=$cities}
<option value="other">other</option>
</select></td>
<td align="left">
<input name="ocity" id="ot" type="text" style="display:none;width:170px" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right"><label for="cons_indi_prof_state">State<span class="req">*</span></label></td>
<td align="left">
<select name="cons_indi_prof_state" id="cons_indi_prof_state" style="width:180px" onChange="display2(this,'oth');">
<option value="Select" selected="selected">Select</option>
{html_options values=$states output=$states}
<option value="other">other</option>
</select></td>
<td align="left">
<input name="ostate" id="oth" type="text" style="display:none;width:170px" maxlength="50" />
</td>
</tr>[/html]

//////////

All codes are working good , cities and states are displaying good in drow-down menu box. Proble is that if user select the city then particular state of that's city will should be display in state drop down menu box.
Pls solve my problem I'm sufffering from 2 weeks.

Thanks
Aug 1 '08 #3
Hi guys,

I 'm developing a site using javascript lib file with prototype, Iframe, smarty , php html, css.. I have read the xml file( city and state ) using CDATASECTION through php and display by smarty in drop down menu . I have one text filed after drop down. i wanna when user select the city from drop down then auto display the state of this city which one user is selecting in the text field.
pls give programe example.

Pls help me.
Aug 8 '08 #4
Can u give the structure of the XML that has the city and state combination.

Are u parsing the XML using javascript or PHP?
Aug 8 '08 #5
Can u give the structure of the XML that has the city and state combination.

Are u parsing the XML using javascript or PHP?


Yes sir, I'm giving below in detail:
-> I'm parsing through PHP

I 'm displaying the cities values in drop-down menu box from cities.xml file for city: field, through smarty and php code , on html form and I have next field is State which is also drop-down menu list box. I want when i select city name from city drop-down then state name of this city will become automatic in state drop-down menu box. currently i'm using saparate xml file for city and state. both xml file are below:

file: cities.xml
Expand|Select|Wrap|Line Numbers
  1. : goes here
  2. <cities>
  3. <city><![CDATA[Abohar]]></city>
  4. <city><![CDATA[Abu Road]]></city>
  5. <city><![CDATA[Adilabad]]></city>
  6. <city><![CDATA[Ariyalur]]></city>
  7. <city><![CDATA[Agartala]]></city>
  8. <city><![CDATA[Agra]]></city>
  9. <city><![CDATA[Ahmedabad]]></city>
  10. <city><![CDATA[Ahmednagar]]></city>
  11. <city><![CDATA[Aizwal]]></city>
  12. <city><![CDATA[Ajmer]]></city>
  13. <city><![CDATA[Ajjampura]]></city>
  14. <city><![CDATA[Akola]]></city>
  15. <city><![CDATA[Aligarh]]></city>
  16. </cities>
[: code goes here for cities]
Expand|Select|Wrap|Line Numbers
  1. function getCities() {
  2. $filename = "cities.xml";
  3. if (file_exists($filename)) {
  4. $cities_obj = simplexml_load_file($filename);
  5. $cities = $cities_obj->xpath('/cities/city');
  6. return $cities;
  7. } else {
  8. echo "File does not exist";
  9. }
  10. }
  11. $cities = getCities();
  12. $main_smarty->assign("cities", $cities);

file: states.xml
Expand|Select|Wrap|Line Numbers
  1. : goes here
  2.  
  3. <states>
  4. <state><![CDATA[Andaman and Nicobar Islands]]></state>
  5. <state><![CDATA[Andhra Pradesh]]></state>
  6. <state><![CDATA[Arunachal Pradesh]]></state>
  7. <state><![CDATA[Assam]]></state>
  8. <state><![CDATA[Bihar]]></state>
  9. <state><![CDATA[Chandigarh]]></state>
  10. <state><![CDATA[Chhattisgarh]]></state>
  11. <state><![CDATA[Dadra and Nagar Haveli]]></state>
  12. <state><![CDATA[Daman and Diu]]></state>
  13. <state><![CDATA[Delhi]]></state>
  14. <state><![CDATA[Goa]]></state>
  15. <state><![CDATA[Gujarat]]></state>
  16. <state><![CDATA[Haryana]]></state>
  17. <state><![CDATA[Himachal Pradesh]]></state>
  18. <state><![CDATA[Jammu and Kashmir]]></state>
  19. <state><![CDATA[Jharkhand]]></state>
  20. <state><![CDATA[Karnataka]]></state>
  21. <state><![CDATA[Kerala]]></state>
  22. </states>
Php:
[Code: ghes here]
Expand|Select|Wrap|Line Numbers
  1. function getStates(){
  2. $filename="states.xml";
  3. if (file_exists($filename)) {
  4. $states_obj = simplexml_load_file($filename);
  5. $states = $states_obj->xpath('/states/state');
  6. return $states;
  7. } else {
  8. echo "File does not exist";
  9. }
  10. }
  11. $states = getStates(); 
  12. $main_smarty->assign("states", $states);

[and HTML CODE GOES HERE] : for city and state ;
[html]
<tr>
<td align="right"><label for="cons_indi_prof_city">City<span class="req">*</span></label></td>
<td align="left">
<select name="cons_indi_prof_city" id="cons_indi_prof_city" style="width:180px" onChange="display(this,'ot');">
<option value="Select" selected="selected">Select</option>
{html_options values=$cities output=$cities}
<option value="other">other</option>
</select></td>
<td align="left">
<input name="ocity" id="ot" type="text" style="display:none;width:170px" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right"><label for="cons_indi_prof_state">State<span class="req">*</span></label></td>
<td align="left">
<select name="cons_indi_prof_state" id="cons_indi_prof_state" style="width:180px" onChange="display2(this,'oth');">
<option value="Select" selected="selected">Select</option>
{html_options values=$states output=$states}
<option value="other">other</option>
</select></td>
<td align="left">
<input name="ostate" id="oth" type="text" style="display:none;width:170px" maxlength="50" />
</td>
</tr>[/html]

//////////

All codes are working good , cities and states are displaying good in drow-down menu box. Proble is that if user select the city then particular state of that's city will should be display in state drop down menu box.
Pls solve my problem I'm sufffering from 2 weeks.

Thanks
Aug 8 '08 #6
acoder
16,027 Expert Mod 8TB
dkyadav80, learn to use code tags properly. I'll show you how:
[CODE=javascript]var test = "test";[/code]

Replace "javascript" with something else for other languages. You can even omit the language, but at the very least use the code tags properly.

I've merged this thread with one you asked earlier since it relates to the same problem.
Aug 8 '08 #7

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

Similar topics

1
by: Laphan | last post by:
Hi All Sorry for the confusing subject, but I'm hoping that you will be able to help. In very basic terms I want to emulate a <SELECT> HTML box in VB. All I want to do is display a title...
4
by: cathy | last post by:
Hi All, I am having problems displaying content relevant to the option selected in a drop-down menu. I have an xml document which is running content through Flash and I need to have the same...
2
by: Krustov | last post by:
If you double click on a empty form box a drop down menu will appear . But if the form box has text content - then double clicking on the form box has no effect and a drop down menu doesnt appear...
2
by: millertime90 | last post by:
Hi basically my problem is I have 2 drop down menus populated by my database the first populated by a field in the database and the 2nd populated with a relation to the value selected in the first...
2
by: pareshppatell | last post by:
Hi there is one problem in firefox droupdown menu when I over drop down menu menu is coming down but is coming down under image or flash what is the problem I can't under stand so please give me...
1
by: saravanabi | last post by:
I want the selected value in javascript from a drop down menu which is designed using the <div> tag... Can anyone help me...
2
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
4
by: coder86 | last post by:
Hi, I am new to this site . I am looking for some help in updating my database from the value selected by user. Heres my page I have a table with rows of ID and its status. Status is a drop...
0
by: buzzard724 | last post by:
Ul li drop down menu works in FF not quite in IE Thank you for looking at this. The page is generated dynamically by php, js and jquery. The drop down menu ul- reports-li - works fine in FF. In...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.