mdattani Posted September 18, 2006 Share Posted September 18, 2006 Hi everyone, I am new to php, and have been using the drop down list example on http://www.plus2net.com/php_tutorial/php_drop_down_list.phpIt is working fine, and comes up with the correct details from the mysql database.However when I click submit, and on my results.php page, i have a $make=$_POST['make']; which is posting the index from the first drop box select name "make",it is actually posting the value "1" when for example "Audi" is selected, instead of the value in the drop down box.I understand that it is posting the index of the value selected, however I want it to post the value of the actual drop down box when it is selected, e.g. "Audi" instead of "1", ("Audi" being index 1 from my database)Any help would be very much appreciated.Thanks people!My code is pasted below;function reload(form){var val=form.make.options[form.make.options.selectedIndex].value;self.location='search.php?make=' + val ;}</script></head><body> <?$quer2=mysql_query("SELECT make,cat_id FROM make order by make"); $make=$HTTP_GET_VARS['make'];if(isset($make) and strlen($make) > 0){$quer=mysql_query("SELECT model FROM model where cat_id=$make order by model"); }else{$quer=mysql_query("SELECT model FROM model order by model"); } echo "<form method=post name=f1 action='results.php'>";echo "<select name='make' onchange=\"reload(this.form)\"><option value=''>Select one</option>";while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['cat_id']==@$make){echo "<option selected value='$noticia2[cat_id]'>$noticia2[make]</option>"."<BR>";}else{echo "<option value='$noticia2[cat_id]'>$noticia2[make]</option>";}}echo "</select>";echo "<select name='model'><option value=''>Select one</option>";while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[model]'>$noticia[model]</option>";}echo "</select>";echo "<input type=submit value=Submit>";echo "</form>"; Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 18, 2006 Share Posted September 18, 2006 <option selected value='$noticia2[cat_id]'>$noticia2[make]</option>This is setting the value to be cat_idIf you want the value to be what you see, you want<option selected >$noticia2[make]</option>OR<option selected value='$noticia2["make"'>$noticia2[make]</option>NOTE: Having no value, will use whats between the option tags Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.