acadia Posted June 22, 2009 Share Posted June 22, 2009 Hi All, I am currently trying to select data from a dropdown menu that then populates other fields. In some ways I have done this. 1. It does populate the drop down 2. the other fields only populate if I choose the last option. with all other options in the dropdown list i get variables undefined. Here is the code: <?php include('config.php'); ?> <?php $query = 'SELECT StudentID, FirstName,NZQANumber,Surname, MiddleName,eMail FROM student '; $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error()); $vbCrLf = "\n"; //create selection list $DropDownList = "<select name='student' id='DropDownListId' onchange='javascript:SelectChanged();'> "; $DropDownList .= "<option value=''></option>".$vbCrLf; while($array = mysql_fetch_array($result)) { $heading = $array['FirstName'].$array['MiddleName'].$array['Surname']; $DropDownList .= "<option value=$heading>$heading</option> ".$vbCrLf; $FirstArrayPhp = 'FirstArray["'.$heading.'"]="'.$array['NZQANumber'].'";'.$vbCrLf; $EmailArrayPhp = 'EmailArray["'.$heading.'"]="'.$array['eMail'].'";'.$vbCrLf; } $DropDownList .= "</select> ".$vbCrLf; ?> <html> <head> <title>Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="Javascript" type="text/javascript"> var FirstArray = new Array(); <?php echo $FirstArrayPhp; ?> var EmailArray = new Array(); <?php echo $EmailArrayPhp; ?> function SelectChanged() { var Student = document.getElementById('DropDownListId').value; document.getElementById('first').value = FirstArray[student]; document.getElementById('email').value = EmailArray[student]; } </script> </head> <body> <form action="" method="post" name="form1" class="style1"> <table width="989" border="1"> <tr> <td>Student Name:</td> <td> <?php echo $DropDownList; ?> </td> <td> </td> </tr> <tr> <td width="150">Student Number:</td> <td width="307"><input type="text" name="first" id="first" class="heading" value="<?php echo $array['first']; ?>"><br /> </td> <!--I need this autopopulated with studentnumber from the database--> <td width="510">This will auto populate after trainer has chosen student for checking it is the right student.</td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" class="date"value="<?php echo $array['email']; ?>"></td> <td>Student course they are on(this should auto populate after trainer chooses student</td> </tr> <tr> <td>Time:</td> <td><input name="Time" type="text" id="Time" size="50" maxlength="50"></td> <td> </td> </tr> <tr> <td>Hours:</td> <td><input name="Hours" type="text" id="Hours" size="50" maxlength="50"></td> <td> </td> </tr> <tr> <td>Comment:</td> <td><input name="Password" type="text" id="Password" size="50" maxlength="50"></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="SubmitNewFacility" id="SubmitNewFacility" value="Submit"></td> </tr> </table> <p> </p> </form> </body> </html> Can you please take a look? Cheers, Chris Quote Link to comment Share on other sites More sharing options...
acadia Posted June 22, 2009 Author Share Posted June 22, 2009 I figured it out it was to do with my dropdown array. Acadia Quote Link to comment Share on other sites More sharing options...
garethhall Posted June 23, 2009 Share Posted June 23, 2009 Are you from NZ ? Have not seen any other New Zealanders on here. Anyway Have you thought of doing the dropdown with an Ajax call? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.