Hi All,
I have created the following form that involves both MYSQL and Javascript in order to allow the user to select a project. At the moment the user selects a student_ID from the selection box and then the project_ID and project_name are described in the following boxes.
The problems I am having are:
- Only the student_IDs show up in the selection box, the project_ID and project_name do not show in the text boxes.
- When the user presses the submit (Join project) button, I want to insert the following values from student_ID and project_ID into a db table called project_assess, that has the following structure:
project_assess_ID - auto generated
project_ID - Needs to come from javascript
lecturer_ID - Will come from $_SESSION variable
lecturer_role - Selected within form
student_ID - Needs to come from javascript
Here is the code:
<form action="modproject.php?action=joinPROJECT" method="post">
<table width="72%" border="0">
<tr bgcolor="#E6E6E6">
<td bgcolor="#E2E2F2"><span class="style2 style1"><strong>Select Lecturer Role</strong></span><span class="style5"><br>
</span></td>
<td bgcolor="#F2F2FF"> <span class="style2">
<input type="radio" name="role" value="Second Marker">
Second Marker
<input type="radio" name="role" value="Third Marker">
Third Marker
<input type="radio" name="role" value="Fourth Marker">
Fourth Marker
</span></td>
</tr>
<tr bgcolor="#E6E6E6">
<td bgcolor="#E2E2F2"><span class="style2 style1"><strong>Select Project</strong></span></td>
<td bgcolor="#F2F2FF">
<?php
$optionsHTML = '';
$optionsJS = "var projectData = new Array();\n";
$query = 'SELECT project_ID, project_name, student_ID FROM student_project';
$result = mysql_query($query) or die("error in query:" . mysql_error());
function jsSafe($str) {
return addslashes(htmlspecialchars(preg_replace("/[\n\r]+/",'', $str)));
}
while($row = mysql_fetch_assoc($result)) {
$optionsHTML .= '<option value="'.$row['student_ID'].'">'.$row['student_ID'].'</option>';
$optionsJS .= sprintf('projectData[%d] = new Array("%s","%s");'."\n",
$row['student_ID'],
jsSafe($row['project_ID']),
jsSafe($row['project_name']));
}
echo '<script type="text/javascript">';
echo $optionsJS;
echo '</script>';
echo '<select onchange="v=eval(this.options[this.selectedIndex].value);this.form.text1.value=projectData[v][0];this.form.text2.value=projectData[v][1];">';
echo $optionsHTML;
echo '</select>';
echo '<input type="text" name="text1" readonly="readonly" />';
echo '<input type="text" name="text2" readonly="readonly" />';
?>
</td>
</table>
<br>
<input type="submit" name="submit" value="Join Project">
</form>