jQuery Get Commands

jQuery Get Commands

Hello,

I have just recently started using jQuery. I am trying to create and index form that asks you to select an option from a drop down box. Once that is selected jQuery pulls data from a php page and pastes it into a div. Once that has been done there are more options available in a select list. Once you select one item the select list beside it fills is more data, so on and so forth.

It script will complete the first query but then when i attempt to run the second query it give me a js error and just sits there.

Any help would be greatly appreciated.

Thanks in advance.

Example of my Code: http://www.codernetworks.com/Magellon/index.php

Below are my code snipits.

sqlqueries.js
  1. $(document).ready(function() { 
  2.       $("#Platform").change(function(event){
  3.             $.get("AJAX/query.php", { TestPlatform: document.getElementById("Platform").value},
  4.                   function(data) {
  5.                         alert("Data Loaded: " + data);
  6.                         $('#query').html(data);
  7.                   }
  8.             );
  9.       });
  10.      
  11.       $("#TestTypeSelect").change(function(event){
  12.             alert ("TestTypeSelected");
  13.             $.get("AJAX/query.php", { TestPlatform: document.getElementById("TestPlan").value, TestType: document.getElementById("TestTypeSelect").value }, 
  14.                   function(data) { 
  15.                         alert("Data Loaded: " + data); 
  16.                         $('#query').html(data); 
  17.                   }
  18.             );
  19.        }); 
  20. });


index.php
  1. <?php
  2.       ///////////////////////
  3.       // Connect to DB
  4.       ///////////////////////
  5.       $nDBInfo = array(
  6.       "Server"=> "**********",
  7.       "Database"=> "*********",
  8.       "UserName"=> "********",
  9.       "Password"=> "******");


  10.       $nDBLink = mysql_connect($nDBInfo['Server'], $nDBInfo['UserName'], $nDBInfo['Password']);
  11.       if (!$nDBLink) {
  12.             die('Could not connect: ' . mysql_error());
  13.       }

  14.       //Select the database we want to use
  15.       mysql_select_db($nDBInfo['Database']) or die("Could not select database");
  16.       mysql_query("set names utf8;");

  17.       //Selects All the Test Plans in `Test_Spec` ....     
  18.       $nSQL = "SELECT DISTINCT(TestPlan) AS 'Test Plans' FROM `Test_Spec` ;";
  19.       $result = mysql_query($nSQL);

  20.       while ($row = mysql_fetch_array($result)) {
  21.             $nOptions .= '<option value="'. $row[0] .'">'. $row[0] .'</option>';
  22.       }
  23.       mysql_close($nDBLink);
  24. ?>
  25. <html>
  26.       <head>
  27.             <script type="text/javascript" src="Javascript/jquery.js"></script>
  28.             <script type="text/javascript" src="Javascript/sqlqueries.js"></script>
  29.       </head>
  30.       <body>
  31.             <form>
  32.                   Select a Test Platform:
  33.                   <select id="Platform" name="users">
  34.                         <option value="Select"> Select </option>
  35.                         <?php echo $nOptions; ?>
  36.                   </select>
  37.             </form>
  38.             <br />
  39.             <div id="query"></div>
  40.       </body>
  41. </html>


query.php

  1. <?php
  2.       $nTestPlan = $_REQUEST["TestPlatform"];
  3.       $nTestType = $_REQUEST["TestType"];
  4.       echo $nTestPlan . "<br>";
  5.       echo $nTestType . "<br>";

  6.       ///////////////////////
  7.       // Connect to DB
  8.       ///////////////////////
  9.       $nDBInfo = array(
  10.       "Server"=> "**********",
  11.       "Database"=> "*********",
  12.       "UserName"=> "********",
  13.       "Password"=> "******");


  14.       $nDBLink = mysql_connect($nDBInfo['Server'], $nDBInfo['UserName'], $nDBInfo['Password']);
  15.       if (!$nDBLink) {
  16.             die('Could not connect: ' . mysql_error());
  17.       }


  18.       //Select the database we want to use
  19.       mysql_select_db($nDBInfo['Database']) or die("Could not select database");
  20.       mysql_query("set names utf8;");
  21.       if ($nTestPlan != ""){
  22.             //Selects All the Test Types in `Test_Data` ....
  23.             $nSQL = "SELECT DISTINCT(TestType) AS 'Test Type' FROM `Test_Data` WHERE `TestPlan` = '".$nTestPlan."' ;";
  24.             $result = mysql_query($nSQL);

  25.             while ($row = mysql_fetch_array($result)) {
  26.                   if ($row[0] == $nTestType & $row[0] != ""){
  27.                         $nOptions .= '<option value="'. $row[0] .'" selected="selected">'. $row[0] .'</option>';
  28.                   }else{
  29.                         $nOptions .= '<option value="'. $row[0] .'">'. $row[0] .'</option>';
  30.                   }           
  31.             }
  32.       }

  33.       if ($nTestType != ""){
  34.             //Selects All the Test Types in `Test_Data` ....
  35.             $nSQL = "SELECT DISTINCT(TestName) AS 'Test Name' FROM `Test_Data` WHERE `TestPlan` = '".$nTestPlan."' AND `TestType` = '".$nTestType."' ;";
  36.             $result = mysql_query($nSQL);

  37.             while ($row = mysql_fetch_array($result)) {
  38.                    $nOptions1 .= '<option value="'. $row[0] .'">'. $row[0] .'</option>';
  39.             }
  40.       }     
  41.       mysql_close($nDBLink);
  42. ?>

  43. <input type="hidden" id="TestPlan" value="<?php echo $nTestPlan; ?>">
  44. <input type="hidden" id="TestType" value="<?php echo $nTestType; ?>">
  45. <select id="TestTypeSelect" size="4" multiple="multiple">
  46.       <?php echo $nOptions; ?>
  47. </select>
  48. <select id="TestName" size="4" multiple="multiple">
  49.       <?php echo $nOptions1; ?>
  50. </select>
  51. <select id="TestResult" size="4" multiple="multiple">
  52.       <option value="1">Pass</option>
  53.       <option value="2">Fail</option>
  54. </select>























    • Topic Participants

    • coder