I am trying to create my first jquery web application, but I ended up at a checkpoint and did not seem to understand this.
I have a PHP page and an HTML page. The HTML page has a triple drop-down list form. The PHP page is connecting to the database, but I'm not sure how to transfer the result of the request from the php page to populate the drop-down list on the html / javascript page.
Here is my code.
HTML:
<script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#selector").submit(function() { $.ajax({ type: "GET", url: "DBConnect.php", success: function(msg){ alert(msg); } }); var select_car_make = $('#select_car_make').attr('value'); var select_car_model = $('#select_car_model').attr('value'); var select_car_year = $('#select_car_year').attr('value'); alert("submitted"); }); </script> <h1 style="alignment-adjust:center">Car information:</h1> <hr /> <div id="results"> <form action="get.php" id="selector" method="get" name="sizer"> <table width="451" height="70" border="0"> <th width="145" height="66" scope="row"><label for="select_car_make"></label> <div align="center"> <select name="select_car_make" id="select_car_make" onchange=""> </select> </div></th> <td width="144"><label for="select_car_model"></label> <div align="center"> <select name="select_car_model" id="select_car_model"> </select> </div></td> <td width="140"><label for="select_car_year"></label> <div align="center"> <select name="select_car_year" id="select_car_year"> </select> </div></td> </tr> </table> <input name="completed" type="submit" value="submit" /> </form>
Here is the PHP page:
<?php $DBConnect = mysqli_connect("localhost", "root", "password", "testing") or die("<p>Unable to select the database.</p>" . "<p> Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "<p>"; echo "<p>Successfully opened the database.</p>"; $SQLString1 = " SELECT car_make FROM cars"; $QueryResult = mysqli_query($DBConnect, $SQLString1)
source share