Gossamer Forum
Home : General : Internet Technologies :

function MM_jumpMenu(targ,selObj,restore

Quote Reply
function MM_jumpMenu(targ,selObj,restore
hi,

I'm using the folowing javascript function to do jump menu using three drop down list..

function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+"testmenu.php?Op_name="+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

the first two works fine. i.e the item selected in the first is used to select the item in the second.

My problem is that i cannot get the secon and third to work properly. can you help.

to clarify:

i have a form with three dropdown list that should contain options comming from a mysql database. the option i select in the first will be used to query the second and populate the second drop down list and so on.

below is my file. Please help!!

<?php
include("../db/dbconnect.php");

if ($Submit)
{
echo $HTTP_POST_VARS['Op_name'];
echo $HTTP_POST_VARS['aircraft_type'];
}else{
/* Get the Operators */

$query_operators = "SELECT DISTINCT Op_name FROM Operator";
$operators_results = mysql_query($query_operators) or die(mysql_error());
$row_operators = mysql_fetch_assoc($operators_results);
$totalRows_operators = mysql_num_rows($operators_results);

$colname_regists = "1";
if (isset($HTTP_GET_VARS['Op_name'])) {
$colname_regists = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['Op_name'] : addslashes($HTTP_GET_VARS['Op_name']);
}

/* get registration*/

$query_regist = sprintf("SELECT Regist_ID,Regist_code FROM Operator,Registration,Aircraft WHERE Operator.Op_ID=Registration.Op_ID and
Op_name='$Op_name'and Aircraft_type='$aircraft_type'", $colname_regists);
$registrations = mysql_query($query_regist) or die(mysql_error());
$row_regists = mysql_fetch_assoc($registrations);
$totalRows_regists = mysql_num_rows($registrations);

/* get aircraft type*/

$query_aircrafts = sprintf("select DISTINCT Aircraft.Aircraft_ID,Aircraft_type from Aircraft,Operator,Registration where
Operator.Op_ID=Registration.Op_ID and Aircraft.Aircraft_ID=Registration.Aircraft_ID and
Op_name='$Op_name'", $colname_regists);
$aircrafts = mysql_query($query_aircrafts) or die(mysql_error());
$row_aircrafts = mysql_fetch_assoc($aircrafts);
$totalRows_aircrafts = mysql_num_rows($aircrafts);

?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+"testmenu.php?Op_name="+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
<!--
function newmenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+"testmenu.php?Op_name=<?php echo $Op_name ?>&aircraft_type="+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->

</script>
</head>

<body>
<form name="form1" method="post" action="<?php echo $PHP_SELF ?>">
<select name="Op_name" onChange="MM_jumpMenu('parent',this,0)">
<option selected value="" <?php if (!(strcmp("", "testmenu.php?Op_name="))) {echo "SELECTED";} ?>><?php echo $HTTP_GET_VARS['Op_name']?></option>
<?php
do {
?>
<option value="<?php echo $row_operators['Op_name']?>"><?php echo $row_operators['Op_name']?></option>
<?php
} while ($row_operators = mysql_fetch_assoc($operators_results));
$rows = mysql_num_rows($operators_results);
if($rows > 0) {
mysql_data_seek($operators_results, 0);
$row_operators = mysql_fetch_assoc($operators_results);
}
?>
</select>
<select name="aircraft_type" onChange="newmenu('parent',this,1)">
<option selected value="" <?php if (!(strcmp("", "testmenu.php?aircraft_type="))) {echo "SELECTED";} ?>></option>
<?php
do {
?>
<option <?php if (!(strcmp($row_aircrafts['Aircraft_ID'], $row_aircrafts['Aircraft_ID']))) {echo "SELECTED";} ?>><?php echo $row_aircrafts['Aircraft_type']?></option>
<?php
} while ($row_aircrafts = mysql_fetch_assoc($aircrafts));
$rows = mysql_num_rows($aircrafts);
if($rows > 0) {
mysql_data_seek($aircrafts, 0);
$row_aircrafts = mysql_fetch_assoc($aircrafts);
}
?>
</select>
<select name="regist">
<?php
do {
?>
<option <?php if (!(strcmp($row_regists['Regist_ID'], $row_regists['Regist_ID']))) {echo "SELECTED";} ?>><?php echo $row_regists['Regist_code']?></option>
<?php
} while ($row_regists = mysql_fetch_assoc($registrations));
$rows = mysql_num_rows($registrations);
if($rows > 0) {
mysql_data_seek($registrations, 0);
$row_regists = mysql_fetch_assoc($registrations);
}
?>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
<?php
mysql_free_result($operators_results);

mysql_free_result($registrations);
}
?>