title: PHP, HTML, jquery onchange
body: <p>I have a dynamic drop down menu and I need to run a jquery code when the user selects an option. </p>
  
  <p>This is the jquery I need to run:</p>
  
  <pre><code>$(function() {
  
      $("select").on("change", function() {
  
          var value = $(this).value(); //get the selected id
          $.get("requesturl.php", {
              course: value
          }, function() {
  
              // do something with the response
          }, "json");
  
      })
  
  })
  </code></pre>
  
  <p>This is my php code:</p>
  
  <pre><code>     if(User('PROFILE')=='admin' || User('PROFILE')=='parent'){
  
  
          $sql=  "SELECT id, course_period_id from schedule WHERE STUDENT_ID='$_SESSION[student_id]'";
  
          $result=mysql_query($sql);
  
          $options="";
  
          while ($row=mysql_fetch_array($result)) {
  
              $id=$row["id"];
              $course_period_id=$row["course_period_id"];
              $course= DBGet(DBQuery("SELECT title FROM course_periods WHERE course_period_id='$course_period_id'"));
              $options.="&lt;OPTION VALUE=\"$course[1]['TITLE']\"&gt;".$course[1]['TITLE'].'&lt;/option&gt;';
  
          }
  
  
          echo "&lt;script type = 'text/javascript'&gt;
                  function populate(course)
              {
                  alert('test');
               }&lt;/script&gt;";
  
  
          echo "&lt;SELECT id='course' name = 'course' onchange='populate(this.course)'  &gt;
              &lt;OPTION VALUE=0&gt;Choose
               $options
  
               &lt;/SELECT&gt;";
  
  
       }
  </code></pre>
  
  <p>I tried to run a test alert inside the jquery but nothing happened when I selected an option.</p>
  
  <p>Please help me, I have no idea how to add the jquery code to my php code.</p>