title: how to display correct data in a text input using jquery
body: <p>Below I have a form which consists of a text input whichs holds details of the student's current course and a course drop down menu which consists of a list of courses.</p>
  
  <pre><code>&lt;form action='editstudent.php' method='post' id='studentForm'&gt;
  &lt;p&gt;&lt;strong&gt;Students:&lt;/strong&gt; &lt;select name="student" id="studentsDrop"&gt;
  &lt;option value=""&gt;Please Select&lt;/option&gt;
  &lt;option value='38'&gt;u0495333 - Jack smith&lt;/option&gt;
  &lt;option value='1'&gt;u0867587 - Mayur Patel&lt;/option&gt;
  &lt;option value='36'&gt;u0867588 - paul smith&lt;/option&gt;
  &lt;/select&gt; &lt;/p&gt;   
  &lt;div id='targetdiv'&gt;&lt;/div&gt; 
  &lt;/form&gt;
  
  
      &lt;form id='editForm'&gt;
  
          &lt;p&gt;&lt;strong&gt;Current Student Details&lt;/strong&gt;&lt;/p&gt;
          &lt;table&gt;
  &lt;tr&gt;
  &lt;th&gt;&lt;/th&gt;
  &lt;td&gt;&lt;input type='hidden' id='currentStudentId' name='StudentIdcurrent' value='' /&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;th&gt;Course:&lt;/th&gt;
          &lt;td&gt;&lt;input type='text' id='currentStudentCourse' name='StudentCoursecurrent' readonly='readonly' value=''/&gt; &lt;/td&gt;
          &lt;/tr&gt;
          &lt;/table&gt;
  
          &lt;p&gt;&lt;strong&gt;New Student Details&lt;/strong&gt;&lt;/p&gt;
          &lt;table&gt;
  &lt;tr&gt;
  &lt;th&gt;&lt;/th&gt;
  &lt;td&gt;&lt;input type='hidden' id='newStudentId' name='StudentIdNew' value='' /&gt; &lt;/td&gt;
  &lt;/tr&gt;
          &lt;tr&gt;
          &lt;th valign='top'&gt;Course:&lt;/th&gt;
          &lt;td id='datacourse' valign='top'&gt;&lt;select name="courses" id="newStudentCourse"&gt;
      &lt;option value=""&gt;Please Select&lt;/option&gt;
      &lt;option value='1'&gt;INFO101 - Bsc Information Communication Technology&lt;/option&gt;
      &lt;option value='2'&gt;INFO102 - Bsc Computing&lt;/option&gt;
      &lt;option value='8'&gt;INFO103 - Business and Finance&lt;/option&gt;
      &lt;option value='7'&gt;INFO104 - English&lt;/option&gt;
      &lt;option value='9'&gt;INFO107 - Mathematics and Stats&lt;/option&gt;
      &lt;option value='16'&gt;INFO120 - Science&lt;/option&gt;
      &lt;/select&gt;
          &lt;div id='studentCourseAlert'&gt;&lt;/div&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;/table&gt;
  
          &lt;/form&gt;
  </code></pre>
  
  <p>Now with the code below it displays the course number and course name in the text input and it selects the student's course from the list of couses in the drop down menu by loacating the course's id.    </p>
  
  <pre><code>$(document).ready( function(){
  
      var studentinfo = [{"StudentId":1,"CourseId":19,"CourseNo":"BIO234","CourseName":"Biology"},
  {"StudentId":38, "CourseId":1,"CourseNo":"INFO101","CourseName":"Bsc Information Communication Technology"},
  {"StudentId":36, "CourseId":8,"CourseNo":"INFO103","CourseName":"Business and Finance"} ];
  
      $('#studentsDrop').change( function(){
  
      var studentId = $(this).val();
  
          if (studentId !== '') {
      for (var i = 0, l = studentinfo.length; i &lt; l; i++)
      {
      if (studentinfo[i].StudentId == studentId) { 
  
  
      var currentcourse = $('#currentStudentCourse').val(studentinfo[i].CourseNo + " - " + studentinfo[i].CourseName);
      var newcourse = $('#newStudentCourse').val(studentinfo[i].CourseId);
  
      $('.courses').val(newcourse);
  
      break;       
      }
      }  
      }
  
      });
  
  });
  </code></pre>
  
  <p>The problem I have is below. I want to update the txt input so that it displays the new course details. But the problem I can't seem to figure out if is that instead of displaying the course number and course name in the text input, it dislays the updated course's id into the text input. Now I know why it is doing this as that <code>jQuery("#currentStudentCourse").val(newStudentCourse);</code> will display the course id value into the text input.  But my question is that how can I use the course id in order to find the id's course number and course name so that I can display the course number and course name in the text input after the update?</p>
  
  <pre><code>function submitform() {    
  
  $.ajax({
  type: "POST",
  url: "updatestudent.php",
  data: $('#editForm').serialize(),
  success: function(html){
  
  var newStudentCourse = jQuery("#newStudentCourse").val();
  
  jQuery("#currentStudentCourse").val(newStudentCourse);
  
  
  }
  });        
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Here is an <a href="http://helios.hud.ac.uk/u0867587/Mobile_app/Text9.php" rel="nofollow">application</a> where you can select a student, then pik a new course and submit it. You will see in the Current Course text input that it changes into a number which is the course id. Jsfiddle which contains the same code is in this jsfiddle: <a href="http://jsfiddle.net/Dst4Q/6/" rel="nofollow">http://jsfiddle.net/Dst4Q/6/</a></p>