Jump to content

Select Data from dropdown menu and populate other fields


acadia

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.