Jump to content

Drop Down list not passing value


mdattani

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 ;
}

</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>";
Link to comment
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>
OR
<option selected value='$noticia2["make"'>$noticia2[make]</option>

NOTE: Having no value, will use whats between the option tags
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.