473,395 Members | 2,079 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,395 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 4760
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.