php - Dropdownlist gets clear when choosing value from this dropdown -
i have created 3 cascading dropdownlist using below html , php code
<?php @$city=$_get['city']; @$locality=$_get['locality'];// use line or below line if register_global off if(strlen($city) > 0 , !is_numeric($city)){ // check if $city numeric data or not. echo "data error"; exit; } if(strlen($locality)>0 , is_numeric($locality)){ echo "data issue"; exit; } ///////// getting data mysql table first list box////////// $quer2=mysql_query("select distinct city_name,city_id city order city_name"); ///////////// end of query first list box//////////// /////// second drop down list check if category selected else display subcategory///// if(isset($city) , strlen($city) > 0){ $quer=mysql_query("select distinct locality_name locality city_id='$city' order locality_name"); }else{$quer=mysql_query("select distinct locality_name locality order locality_name"); } ////////// end of query second subcategory drop down list box /////////////////////////// echo "<form method=post name=f1>"; /// add form processing page address action in above line. example action=dd-check.php//// ////////// starting of first drop downlist ///////// echo "<select name='city' onchange=\"localityload(this.form)\"><option value=''>select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['city_id']==@$city){echo "<option selected value='$noticia2[city_id]'>$noticia2[city_name]</option>"."<br/>";} else{echo "<option value='$noticia2[city_id]'>$noticia2[city_name]</option>";} } echo "</select>"; ////////////////// end first drop down list /////////// ////////// starting of second drop downlist ///////// echo "<select name='locality' id='locality' onchange=\"localityload(this.form);\"><option selected value=''>select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[locality_name]' >$noticia[locality_name]</option>"; } echo "</select>"; if(isset($locality) , strlen($locality)>0) { $query=mysql_query("select distinct specialization drsignup locality_name='$locality'"); } else {$query=mysql_query("select distinct specialization drsignup");} echo "<select name='specialization'>"; echo "<option selected='selected' value='specialist in'>specialist in</option>"; while($notic = mysql_fetch_array($query)) { echo "<option value='$notic[specialization]'>$notic[specialization]</option>"; } echo "</select>"; <!--<input type="submit" name="submit" value="signup" />--> echo "</form>"; ?>
i using below javascript function onchange event city , locality dropdown list
<script language=javascript> function localityload(form) { var val=form.city.options[form.city.options.selectedindex].value; var val2=form.locality.options[form.locality.options.selectedindex].value; self.location='city-loc.php?city=' + val + '& locality=' +val2; form.locality.options[form.locality.options.selectedindex].selected=true; } </script>
when select city first dropdown,second drop down populate corresponding locality name , when select gets clear selection .the third dropdown list selected based on first , second selection , retains there.
please let me know solution retain second dropdown value.
i'm no php expert, think see issue . . .
when call code in javascript:
self.location='city-loc.php?city=' + val + '& locality=' +val2;
you reload page 2 selections first 2 <select>
dropdowns passed variables. then, when page reloads, use code:
if ($noticia2['city_id']==@$city) { echo "<option selected value='$noticia2[city_id]'>$noticia2[city_name]</option>"."<br/>"; }
. . . set selected value when building first dropdown if option value matches city
parameter in url.
however, don't have similar statement check locality
parameter url when building second dropdown. so, though have passed parameter (and capture here: @$locality=$_get['locality'];
), there no code use figure out locality
option should selected default, when page reloads.
like said, i'm not php, i'd imagine needed, when building second dropdown:
if ($noticia['locality_name']==@$locality) { echo "<option selected value='$noticia[locality_name]'>$noticia[locality_name]</option>"."<br/>"; }
Comments
Post a Comment