|  | Posted by Ian Davies on 11/23/05 00:06 
HelloI have found the following script php/java for dynamic menu lists. Where a
 selection from the first updates (filters items in) the other. I have
 modified it for my tables.
 However I am getting an error
 
 Parse error: parse error, unexpected T_VAR in
 e:\domains\i\iddsoftware.co.uk\user\htdocs\QuestionDB\Questions.php on line
 42
 
 line 42 being
 var mainselect = document.FormName.MainCategory;
 
 Im fairly new to php and dont use Java upto now. Can anyone see where I ve
 gone wrong
 
 <?php
 session_start();
 include("../include/connection.php");
 include("../Secure/login.php");
 $Heading= 'QUESTION SELECTOR';
 $Menu='<a href="../Secure/logout.php">Logout</a><br>';
 include 'HeadQuest.php';
 
 
 $Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
 StatusID = 1 ORDER BY SubjectDesc ASC";
 $Result = mysql_query( $Query, $conn );
 
 ?>
 
 <HTML>
 <HEAD>
 <SCRIPT language="JavaScript">
 
 function BodyLoad()
 {
 
 var select = document.FormName.MainCategory;
 
 select.options[0] = new Option("Choose One");
 select.options[0].value = 0;
 
 <?PHP
 
 $ctr = 1;
 While( $Row = mysql_fetch_array($Result) ) {
 echo "select.options[".$ctr."] = new
 Option(\"".$Row['SubjectNo']."\");\n";
 echo "select.options[".$ctr."].value = \"".$Row['SubjectNo']."\";\n";
 $ctr++;
 }
 ?>
 }
 
 function Fill_Sub()
 {
 
 <?PHP
 var mainselect = document.FormName.MainCategory;
 var subselect = document.FormName.SubCategory;
 
 if( mainselect.options[mainselect.selectedIndex].value != 0 ) {
 
 subselect.length = 0;
 }
 
 $Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
 StatusID = 1 ORDER BY SubjectDesc ASC";
 $Result = mysql_query($Query, $conn );
 
 while( $Row = mysql_fetch_array($Result) ) {
 ?>
 
 
 if( mainselect.options[mainselect.selectedIndex].text == "<?PHP echo
 $Row['SubjectNo']; ?>" ) {
 <?PHP
 
 $Query2 = "SELECT TopicID, TopicDesc, KS, SubjectNo FROM ttopic WHERE
 StatusID = 1 AND SubjectNo = ".$row['SubjectNo']." ORDER BY TopicDesc ASC";
 
 
 $Result2 = mysql_query($Query2, $conn );
 
 $ctr = 0;
 
 While( $Row2 = mysql_fetch_array($Result2) ) {
 echo "subselect.options[".$ctr."] = new
 Option(\"".$Row2['TopicID']."\");\n";
 echo "subselect.options[".$ctr."].value =
 \"".$Row2['TopicID']."\";\n";
 $ctr++;
 }
 ?>
 }
 }
 
 <?PHP
 }
 
 mysql_close($conn);
 ?>
 }
 
 </SCRIPT>
 </HEAD>
 
 <BODY onload="BodyLoad();">
 <FORM name="FormName" method="POST" action="">
 <TABLE border="1">
 <TR>
 <TD>Main Category</TD>
 <TD>Sub Category</TD>
 </TR>
 <TR>
 <TD>
 <SELECT name="MainCategory" onchange="Fill_Sub();">
 </SELECT>
 </TD>
 
 <TD>
 <SELECT name="SubCategory" size="4">
 </SELECT>
 </TD>
 </TR>
 </TABLE>
 </FORM>
 </BODY>
 </HTML>
 [Back to original message] |