Hi All,
I’m wanting to have 2 select boxes go to showproducts.php page. Below is my code. Do I need 2 functions, or, can I do an if in the function go()..?
Javascript Code:
<script lanaguage=”javascript”>
function go()
{
box = document.forms[0].navi;
destination = box.options[box.selectedIndex].value;
if (destination) location.href = destination;
}
</script>
HTML/PHP Code:
<form>
<table align=”center” border=”2″>
<tr>
<td><h3 align=center>PRODUCT TYPE</h3></td>
</tr>
<tr><td><center>
<?php
$db = mysql_connect(“localhost”, “root”, “grunger”);
mysql_select_db(“status”,$db);
$result = mysql_query(“SELECT ProductTypes.product_type_detail, ProductTypes.product_type_id FROM ProductTypes”,$db);
$num = mysql_num_rows($result);
?>
<select name=”slct_product_type” onChange=”go()”>
<option value””>Make A Selection</option>
<?php
for ($i=0; $i<$num; $i++){
$myrow=mysql_fetch_array($result);
$product_type=mysql_result($result,$i,”product_type_detail”);
$product_type_id=mysql_result($result,$i,”product_type_id”);
echo “<option value=”showproducts.php?id=$product_type_id”>$product_type</option><br>”;
}
?>
</select>
</center>
</td></tr>
</table>
<table align=”center” border=”2″>
<tr>
<td><h3 align=center>MAKER</h3></td>
</tr>
<tr><td><center>
<?php
$maker_result = mysql_query(“SELECT Makers.maker_id, Makers.maker_detail FROM Makers”,$db);
if (!$maker_result) die(mysql_error());
?>
<select name=”slct_maker” onChange=”go()”>
<option value=””>Make A Selection</option>
<?php
$maker_num = mysql_num_rows($maker_result);
for ($i=0; $i<$maker_num; $i++){
$myrow=mysql_fetch_array($maker_result);
$maker=mysql_result($maker_result,$i,”maker_detail”);
$maker_id=mysql_result($maker_result,$i,”maker_id”);
echo “<option value=”showproducts.php?id=$maker_id”>$maker</option><br>”;
}
?>
</select>
</center>
</td></tr>
</table>
</form>