title: Document never becomes ready to get information from database
body: <p>Basically the problems that I am having is that I have a section of script that is set to execute when the select box "graded" changes. Basically what happens in the document never becomes ready. When I use Chrome's console to print out the studentid and graderid values they are empty. I put an "exit();" function in the displayeval.php page and was able to find out that the document never becomes ready.</p>
  
  <p>I realize a lot of this code is messed up and very novice, but I am working like a crazy man to finish up this project before the end of the week for class and I just want it to work.</p>
  
  <pre><code>$(document).ready(function () {
      $('#graded').change(function () {
          var studentid = $('#studentid').val();
          var graderid = $(this).val();
          $.get("displayeval.php?graderid=" + graderid + "&amp;studentid=" + studentid, function (data) {
              $('#behavior-290').val(data.comment);
          }, "json");
      });
  });
  </code></pre>
  
  <p>instructoreval.php</p>
  
  <pre><code>    &lt;?php
  include('includes/header.php');
  $student_id=$_GET['studentid'];
  if($session-&gt;userlevel&gt;=8)
  
  //if they are an instructor
  {
   if(isset($_POST['Submit'])){
        $query="SELECT * FROM Behavior b, Groups g WHERE g.GROUP_ID=" . $session-&gt;GROUP_ID . " AND b.CONTRACT_ID=g.CONTRACT_ID";
        $btwo = mysql_query($query) or die(mysql_error());
        $numB = mysql_num_rows($btwo);
        $query2="INSERT INTO Eval (STUDENT_ID, Grader_ID, GROUP_ID, Grade) VALUES (" . $_POST[graded] . ", " . $session-&gt;STUDENT_ID . ", " . $session-&gt;GROUP_ID . ", '10')";
        mysql_query($query2) or die(mysql_error());
  
        $evalid = mysql_insert_id();
        for($i=0;$i&lt;$numB;$i++){ 
          $r2 = mysql_fetch_array($btwo);
          $query3="INSERT INTO EvalComment (CONTRACT_ID, BEHAVIOR_ID, Comment, EVAL_ID) VALUES (" . $r2[CONTRACT_ID] . ", " . $r2[BEHAVIOR_ID] . ", \"" . $_POST[$r2[BEHAVIOR_ID]] . "\", " . $evalid . ")";
          mysql_query($query3) or die(mysql_error());
        };
        $qfour = mysql_query("SELECT * FROM users WHERE GROUP_ID=" . $session-&gt;GROUP_ID . " AND STUDENT_ID=" . $_POST[graded]);
        $rfour = mysql_fetch_array($qfour);
        popup("Your comments for " . $rfour[lname] . ", " . $rfour[fname] . " have been submitted.");
      };
  
  
              $link = mysql_connect("localhost","drallen1","unicode") or die(mysql_error);
              mysql_select_db("drallen1");
  
              $qsix = mysql_query("SELECT * FROM users u WHERE u.GROUP_ID=" . $session-&gt;GROUP_ID . " AND NOT EXISTS(SELECT * FROM Eval e WHERE u.STUDENT_ID=e.STUDENT_ID) AND u.STUDENT_ID!=" . $session-&gt;STUDENT_ID);
              $numE = mysql_num_rows($qsix);
              /***************************************************
              //WHEN numE == 0 GO TO PIE CHART
              ***************************************************/
              //QUERY
              $qtwo = mysql_query("SELECT * FROM Behavior b, Groups g WHERE g.GROUP_ID=" . $session-&gt;GROUP_ID . " AND b.CONTRACT_ID=g.CONTRACT_ID");
               // match eval id
              $numB = mysql_num_rows($qtwo);
  
              if($numE&gt;1)
                $page="evalform.php";
              else
                $page="evalprocess.php";
  
                echo "&lt;form action=$page method=\"POST\"&gt;";?&gt;
  
              &lt;script type="text/javascript"&gt;
                  $(document).ready(function(){
                              $('#graded').change(
                                  function() {
                                  var studentid = $('#studentid').val();
                                  var graderid = $(this).val();
  
                                  $.get( "displayeval.php?graderid=" + graderid + "&amp;studentid=" + studentid,
                                     function(data){
                                          $('#behavior-290').val(data.comment);
                                     }, "json");
                              });
                      });
          &lt;/script&gt;
              &lt;input type="hidden" name="studentid" id="studentid" value="&lt;?php echo $_GET['studentid'];?&gt;" /&gt;
              Student: &lt;select name="graded" id="graded"&gt;
                &lt;option selected="selected"&gt;Please Select a Student to Grade&lt;/option&gt;
                &lt;?php for($i=0;$i&lt;$numE;$i++){
                  $rsix = mysql_fetch_array($qsix);?&gt;
                  &lt;option value="&lt;?php echo $rsix[STUDENT_ID]?&gt;"&gt;&lt;?php echo $rsix[fname] . " " . $rsix[lname]?&gt;&lt;/option&gt;
                &lt;?php };?&gt;
              &lt;/select&gt;&lt;/br&gt;&lt;/br&gt;
  
              &lt;!--$qthree = mysql_query("SELECT EVAL_ID FROM Eval WHERE GRADER_ID=" . $student_id. " AND STUDENT_ID=" . graded.value ); --&gt;
  
              &lt;?php for($i=0;$i&lt;$numB;$i++){ 
              //result of qtwo
                $rtwo = mysql_fetch_array($qtwo);
                echo "Behavior: &lt;input name=\"BEHAVIOR_ID\" type=\"text\" value=\"" . $rtwo[BehaviorName] . "\" readonly=\"readonly\"/&gt; &lt;/br&gt;";
  
                  //$queryshit="SELECT Comment FROM EvalComment WHERE EVAL_ID=RESULTFROMQTHREE AND BEHAVIOR_ID=" . $rtwo[BEHAVIOR_ID];
                  //$comments;
  
                echo "Comments: &lt;textarea name=\"" . $rtwo['BEHAVIOR_ID'] . "\" id=\"behavior-" . $rtwo['BEHAVIOR_ID'] . "\" rows=\"5\" cols=\"50\"&gt;". $comments . "&lt;/textarea&gt; &lt;/br&gt;"; ?&gt;
              &lt;?php };?&gt;
              &lt;/br&gt;
              &lt;input type="submit" value="Send!" name="Submit"/&gt;
            &lt;/form&gt;
          &lt;/body&gt;
  
     &lt;/html&gt;
  
      &lt;? include("includes/footer.php"); 
    }else{
    echo "You don't have access to this.";
  };?&gt;
  </code></pre>
  
  <p>displayeval.php</p>
  
  <pre><code>    &lt;?php
  include('include/session.php');
  
  
  $grader_id=$_GET['graderid'];
  $student_id=$_GET['studentid'];
  
  $query="SELECT EVAL_ID FROM Eval WHERE GRADER_ID=". $grader_id . " AND STUDENT_ID=" . $student_id;
  
  $result=mysql_query($query) or die(mysql_error());
  $data=mysql_fetch_array($result);
  
  $eval_id=$data['EVAL_ID'];
  
  $query="SELECT BEHAVIOR_ID,Comment comment FROM EvalComment WHERE EVAL_ID=". $eval_id;
  $result=mysql_query($query) or die(mysql_error());
  
  $data2=mysql_fetch_assoc($result);
  //print_r($data2);
  
  
  // query database based on GET params
  
  // fetch result
  // $mysql_row = mysql_fetch_assoc()
  
  // display in JSON: 
  echo json_encode( $data2 );
  </code></pre>
  
  <p>this is the result of the displayeval(displayeval.php?graderid=0&amp;studentid=241654664) page </p>
  
  <pre><code>{"BEHAVIOR_ID":"1","comment":"Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write Write"}
  </code></pre>