mjfroggy
11-25-2005, 12:14 PM
Hello,
I got this code off another post here. what I am trying to do is have a select box called slots where you select a number then the second listbox will load with the matching price for that number. both list boxes call its values from a database. When the user selects a value from that list box it will cause another listbox to open with other values called from the database. Actually ideally I would like the second listbox to be an uneditable textbox but a select box is fine as well:-)
Anyway the first list box does call the dbase values but then it does not load the second select box when you click on a value on the first select box? Insead I get an "object expected error" on line 100 which would be the line where it says $result1=mysql_query("select * from price Where slots='".$row['slots']."'");
HERE IS MY FULL CODE (thanks for any help)
<?
$link = mysql_connect("localhost", "***", "**");
mysql_select_db("***");
echo "<SCRIPT LANGUAGE='JavaScript'>";
$query = "SELECT slots,price FROM slots";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
echo "\nvar arr".$row['price']."Array = new Array(\"('Select price')\",";
$result1=mysql_query("select * from price Where slots='".$row['slots']."'");
$num=mysql_num_rows($result1);
$i=0;
while($row1=mysql_fetch_array($result1))
{
$i++;
echo "\n\"('".$row1['price'];
if($i<$num) echo "')\",";
else echo "')\")";
}
}
echo "function populateList(inForm,selected)
{
var selectedArray = eval(selected + \"Array\");
while (selectedArray.length < inForm.price.options.length)
inForm.divisions.options[(inForm.price.options.length - 1)] = null;
for (var i=0; i < selectedArray.length; i++)
eval(\"inForm.price.options[i]=\" + \"new Option\" + selectedArray[i]);
}
</script>";
?>
<select name="slots" onChange="populateList(document.form1,document.form1.slots.options[document.form1.slots.selectedIndex].value)">
<option selected value=''># OF SLOTS</option>
<?
$query1 = "SELECT * FROM slots";
$result1 = mysql_query($query1) or die('aa');
while($row=mysql_fetch_array($result1))
echo "<option value='arr".$row['slots']."'>".$row['slots']."</option>";
?>
</select>
I got this code off another post here. what I am trying to do is have a select box called slots where you select a number then the second listbox will load with the matching price for that number. both list boxes call its values from a database. When the user selects a value from that list box it will cause another listbox to open with other values called from the database. Actually ideally I would like the second listbox to be an uneditable textbox but a select box is fine as well:-)
Anyway the first list box does call the dbase values but then it does not load the second select box when you click on a value on the first select box? Insead I get an "object expected error" on line 100 which would be the line where it says $result1=mysql_query("select * from price Where slots='".$row['slots']."'");
HERE IS MY FULL CODE (thanks for any help)
<?
$link = mysql_connect("localhost", "***", "**");
mysql_select_db("***");
echo "<SCRIPT LANGUAGE='JavaScript'>";
$query = "SELECT slots,price FROM slots";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
echo "\nvar arr".$row['price']."Array = new Array(\"('Select price')\",";
$result1=mysql_query("select * from price Where slots='".$row['slots']."'");
$num=mysql_num_rows($result1);
$i=0;
while($row1=mysql_fetch_array($result1))
{
$i++;
echo "\n\"('".$row1['price'];
if($i<$num) echo "')\",";
else echo "')\")";
}
}
echo "function populateList(inForm,selected)
{
var selectedArray = eval(selected + \"Array\");
while (selectedArray.length < inForm.price.options.length)
inForm.divisions.options[(inForm.price.options.length - 1)] = null;
for (var i=0; i < selectedArray.length; i++)
eval(\"inForm.price.options[i]=\" + \"new Option\" + selectedArray[i]);
}
</script>";
?>
<select name="slots" onChange="populateList(document.form1,document.form1.slots.options[document.form1.slots.selectedIndex].value)">
<option selected value=''># OF SLOTS</option>
<?
$query1 = "SELECT * FROM slots";
$result1 = mysql_query($query1) or die('aa');
while($row=mysql_fetch_array($result1))
echo "<option value='arr".$row['slots']."'>".$row['slots']."</option>";
?>
</select>
