Forum Moderators: open

Message Too Old, No Replies

Creating a Form that has two List Menu Elements

Second List Refreshes based on first List/Menu Element

         

gms3651

12:32 am on Mar 17, 2007 (gmt 0)

10+ Year Member



Hello,
I have a form that contains two List/Menu Elements. I want it created so that when a option is selected in the first form element then the second form gets populated with certain value that are specific to the first List/Menu element.

For example../The first form is going to contain a List of Area Rug manufacturers such as Milliken, Shaw, and Sphinx. If the user selects Milliken then the second form gets populated with all the collections of the Milliken Manufacturer. If the user selects Shaw then the second form gets populated with all the collections of the Shaw Manufacturer.

The collection List/Menu's are going to be populated by querying a db table using PHP and MySql.

gms3651

1:42 am on Mar 17, 2007 (gmt 0)

10+ Year Member



Ok...I'm currently just trying to get the first List/Menu to populate. When the page loads I call this JavaScript function. However I'm getting a JavaScript error when I'm inside the while statement.

function OnChange()
{ document.form1.select1.options.length=0
var i = 0;
<?php
$dbcnx = @mysql_connect('localhost', 'username', 'password');
@mysql_select_db("table", $dbcnx);
$manufacturers = @mysql_query("Select id, manufacturer from manufacturers");
while ($manufacturer = mysql_fetch_array($manufacturers))
{?>
document.form1.select1.options[i]=new Option(<?php echo $manufacturer['manufacturer'];?>, <?php echo $manufacturer['manufacturer'];?>", true, false)
i = i + 1
<?php
}
?>
}

Is the Syntax correct?

gms3651

2:49 am on Mar 17, 2007 (gmt 0)

10+ Year Member



Ok...I got that problem fixed. Now I'm onto another problem. I am passing a value to a JavaScript function. However, i need to use that parameter in my mysql_query. I don't know how to include my JavaScript parameter into my PHP mysql_query statement. Below is my code:

function manuChange(thestuff)
{alert(thestuff);
document.form1.select2.options.length=0
var i = 0
<?php
$dbcnx = @mysql_connect('localhost', 'username', 'password');
@mysql_select_db("table", $dbcnx);
$collections = @mysql_query("Select id, collection from collections where manuID='notsure'");
while ($collection = mysql_fetch_array($collections))
{?>
document.form1.select2.options[i]=new Option("<?php echo "$collection[collection]";?>", "<?php echo "$collection[collection]";?>", true, false)
i = i + 1
<?php
}
?>
}

This is the line that is giving me trouble

$collections = @mysql_query("Select id, collection from collections where manuID='notsure'");

I don't know how to get my JavaScript 'thestuff' variable into the mysql_query statement.

Thanks