Jump to content


Photo

Drop Down list not passing value


  • Please log in to reply
1 reply to this topic

#1 mdattani

mdattani
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 September 2006 - 08:01 PM

Hi everyone, I am new to php, and have been using the drop down list example on http://www.plus2net....p_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>";


#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 18 September 2006 - 09:04 PM

<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
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users