473,699 Members | 3,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

21 New Member
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 4808
acoder
16,027 Recognized Expert Moderator MVP
What have you managed so far? This is the classical dependent drop-down problem. Post your code.
Jul 19 '08 #2
dkyadav80
21 New Member
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($f ilename)) {
$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_p rof_city" style="width:18 0px" onChange="displ ay(this,'ot');" >
<option value="Select" selected="selec ted">Select</option>
{html_options values=$cities output=$cities}
<option value="other">o ther</option>
</select></td>
<td align="left">
<input name="ocity" id="ot" type="text" style="display: none;width:170p x" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right">< label for="cons_indi_ prof_state">Sta te<span class="req">*</span></label></td>
<td align="left">
<select name="cons_indi _prof_state" id="cons_indi_p rof_state" style="width:18 0px" onChange="displ ay2(this,'oth') ;">
<option value="Select" selected="selec ted">Select</option>
{html_options values=$states output=$states}
<option value="other">o ther</option>
</select></td>
<td align="left">
<input name="ostate" id="oth" type="text" style="display: none;width:170p x" 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
dkyadav80
21 New Member
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
newlearner
67 New Member
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
dkyadav80
21 New Member
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_p rof_city" style="width:18 0px" onChange="displ ay(this,'ot');" >
<option value="Select" selected="selec ted">Select</option>
{html_options values=$cities output=$cities}
<option value="other">o ther</option>
</select></td>
<td align="left">
<input name="ocity" id="ot" type="text" style="display: none;width:170p x" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right">< label for="cons_indi_ prof_state">Sta te<span class="req">*</span></label></td>
<td align="left">
<select name="cons_indi _prof_state" id="cons_indi_p rof_state" style="width:18 0px" onChange="displ ay2(this,'oth') ;">
<option value="Select" selected="selec ted">Select</option>
{html_options values=$states output=$states}
<option value="other">o ther</option>
</select></td>
<td align="left">
<input name="ostate" id="oth" type="text" style="display: none;width:170p x" 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 Recognized Expert Moderator MVP
dkyadav80, learn to use code tags properly. I'll show you how:
[CODE=javascrip t]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
1869
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 name in the drop-down list, but the actual value I use would be something else.
4
3970
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 content on a web page. I am working in Dreamweaver 8 and code in asp.net (vb). I need to have a drop-down menu listing available news articles, when one is selected the article should appear on the page. I have currently managed to populate the...
2
1779
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 . Or at least it doesnt in IE v7 . A google search only really brought up the usual beginner type of form tutorials .
2
2854
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 and basically i'm just havin a problem refreshing the menus after i submit a value or refresh the page. My code is below: //javascript <script language="JavaScript"> function autoSubmit() { var formObject = document.forms; ...
2
2005
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 solution for these. It is working ie is properly
1
3435
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
3091
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 that dynamically pulls info from my database to populate a drop down menu. Upon an onChange event, I wish to display the fields related to that pull down menu WITHOUT SUBMITTING THE PAGE. The Senario: Database name: sp.mdb
4
10754
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 down menu with 4 possible options. The default displayed is the value from database. When the user picks a value form drop down menu say "completed" I want this value to be updated fro that particular id to database. Heres my script to create drop...
0
2197
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 IE7 the menu displays and if I am very very careful with how I move the mouse I can sometimes manage to catch the submenu - particularly the first time the page is displayed. Usually the menu disappears before I can mouse over it. I guess this is...
0
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9187
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8894
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.