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
-
<cities>
-
<city><![CDATA[Abohar]]></city>
-
<city><![CDATA[Abu Road]]></city>
-
<city><![CDATA[Adilabad]]></city>
-
<city><![CDATA[Ariyalur]]></city>
-
<city><![CDATA[Agartala]]></city>
-
<city><![CDATA[Agra]]></city>
-
<city><![CDATA[Ahmedabad]]></city>
-
<city><![CDATA[Ahmednagar]]></city>
-
<city><![CDATA[Aizwal]]></city>
-
<city><![CDATA[Ajmer]]></city>
-
<city><![CDATA[Ajjampura]]></city>
-
<city><![CDATA[Akola]]></city>
-
<city><![CDATA[Aligarh]]></city>
-
</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
-
-
<states>
-
<state><![CDATA[Andaman and Nicobar Islands]]></state>
-
<state><![CDATA[Andhra Pradesh]]></state>
-
<state><![CDATA[Arunachal Pradesh]]></state>
-
<state><![CDATA[Assam]]></state>
-
<state><![CDATA[Bihar]]></state>
-
<state><![CDATA[Chandigarh]]></state>
-
<state><![CDATA[Chhattisgarh]]></state>
-
<state><![CDATA[Dadra and Nagar Haveli]]></state>
-
<state><![CDATA[Daman and Diu]]></state>
-
<state><![CDATA[Delhi]]></state>
-
<state><![CDATA[Goa]]></state>
-
<state><![CDATA[Gujarat]]></state>
-
<state><![CDATA[Haryana]]></state>
-
<state><![CDATA[Himachal Pradesh]]></state>
-
<state><![CDATA[Jammu and Kashmir]]></state>
-
<state><![CDATA[Jharkhand]]></state>
-
<state><![CDATA[Karnataka]]></state>
-
<state><![CDATA[Kerala]]></state>
-
</states>
Php:
-
-
function getStates(){
-
$filename="states.xml";
-
if (file_exists($filename)) {
-
$states_obj = simplexml_load_file($filename);
-
$states = $states_obj->xpath('/states/state');
-
return $states;
-
} else {
-
echo "File does not exist";
-
}
-
}
-
$states = getStates();
-
$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