I am creating a script where I am able to edit student details. So what happens is that I select a student from a list of students in a drop down menu which is compiled with the code below:\[code\]<?php$studentquery = " SELECT StudentId, StudentUsername, StudentDOB, s.CourseId, CourseNo, CourseName FROM Student s INNER JOIN Course c ON s.CourseId = c.CourseId ORDER BY StudentAlias ";$studentqrystmt = $mysqli->prepare($studentquery);// You only need to call bind_param once$studentqrystmt->bind_param("i", $active);// get result and assign variables (prefix with db)$studentqrystmt->execute();$studentqrystmt->bind_result($dbStudentId, $dbStudentUsername, $dbStudentDOB, $dbCourseId, $dbCourseNo, $dbCourseName);$studentqrystmt->store_result();$studentnum = $studentqrystmt->num_rows();$studentHTML = '<select name="student" id="studentsDrop">' . PHP_EOL;$studentHTML .= '<option value="">Please Select</option>' . PHP_EOL;$studentInfo = array();while ($studentqrystmt->fetch()) { $studentHTML .= sprintf("<option value='http://stackoverflow.com/questions/14043370/%s'>%s</option>", $dbStudentId, $dbStudentUsername) . PHP_EOL; $studentData = http://stackoverflow.com/questions/14043370/array(); $studentData["StudentId"] = $dbStudentId; $studentData["StudentUsername"] = $dbStudentUsername; $studentData["StudentDOB"] = date("d-m-Y", strtotime($dbStudentDOB)); $studentData["CourseNo"] = $dbCourseNo; $studentData["CourseName"] = $dbCourseName; array_push($studentInfo, $studentData);}$studentHTML .= '</select>';$studentForm = " <form action='" . htmlentities($_SERVER['PHP_SELF']) . "' method='post' id='studentForm'> <p>{$studentHTML}</p> </form> ";echo $studentForm;\[/code\]Now what happens is that when a user is selected, it displays all of the details of the student in a form in relevant text inputs:\[code\] $('#studentsDrop').change( function(){ var studentId = $(this).val(); if (studentId !== '') { for (var i = 0, l = studentinfo.length; i < l; i++) { if (studentinfo.StudentId == studentId) { var currentid = $('#currentStudentId').val(studentinfo.StudentId); var currentusername = $('#currentStudentUsername').val(studentinfo.StudentUsername); var currentdob = $('#currentStudentDOB').val(studentinfo.StudentDOB); var currentcourse = $('#currentStudentCourse').val(studentinfo.CourseNo + " - " + studentinfo.CourseName); var newcourse = $('#newStudentCourse').val(courseinfo.CourseId); break; } } } });}); \[/code\]Now this works expect for this line: \[code\]var newcourse = $('#newStudentCourse').val(courseinfo.CourseId);\[/code\]What I am trying to do with the line above is that when a student is selected,, it will select the course the user is currently studying in the course drop down menu below out of the list of course. The problem is that instead what it is doing is that when a student is selected, it just selects the first course option in the course drop down menu. My question is that out of the list of courses in the drop down menu below, how can I get the student's course to be selected in the course drop down menu after a student is selected?Below is the code for the course drop down menu:\[code\] $sql = "SELECT CourseId, CourseNo, CourseName FROM Course ORDER BY CourseNo"; $sqlstmt=$mysqli->prepare($sql); $sqlstmt->execute(); $sqlstmt->bind_result($dbCourseId, $dbCourseNo, $dbCourseName); $courses = array(); // easier if you don't use generic names for data $courseHTML = ""; $courseHTML .= '<select name="courses" id="newStudentCourse">'.PHP_EOL; $courseHTML .= '<option value="">Please Select</option>'.PHP_EOL; $courseInfo = array(); while($sqlstmt->fetch()) { $course = $dbCourseId; $courseno = $dbCourseNo; $coursename = $dbCourseName; if ($validSubmission && $course == $_POST['courses']) { $courseHTML .= "<option value='".$course."' selected='selected'>" . $courseno . " - " . $coursename . "</option>".PHP_EOL; } else { $courseHTML .= "<option value='".$course."'>" . $courseno . " - " . $coursename . "</option>".PHP_EOL; }$courseData = http://stackoverflow.com/questions/14043370/array();$courseData["CourseId"] = $dbCourseId;array_push($courseInfo, $courseData); } $courseHTML .= '</select>'; $editstudent = "<form id='editForm'><p><strong>New Student Details</strong></p><table><tr><th valign='top'>Course:</th><td id='datacourse' valign='top'>{$courseHTML}</td></tr></table></form>";echo $editstudent;\[/code\]