Jump to content


This topic is now archived and is closed to further replies.


Drop Down list not passing value

Recommended Posts

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.php
It 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 ;




$quer2=mysql_query("SELECT make,cat_id FROM make order by 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>";

Share this post

Link to post
Share on other sites
<option selected value='$noticia2[cat_id]'>$noticia2[make]</option>
This is setting the value to be cat_id
If you want the value to be what you see, you want

<option selected >$noticia2[make]</option>
<option selected value='$noticia2["make"'>$noticia2[make]</option>

NOTE: Having no value, will use whats between the option tags

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.