Monday, 26 August 2013

using JQuery to change a second drop down selection box from mysql DB

using JQuery to change a second drop down selection box from mysql DB

I am trying to get the second dropdown box to change and populate when the
first box has a car Make chosen. It connects to the database just fine,
and if I type 'Honda' instead of 'carmake3' in the second dropdown, then
it gives me a list of all the honda cars. I just need to work based on
what the user selects. Any help would be extremely appreciated!
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<form action="step-3" method="post">
Car 3
</div>
<?php
mysql_connect('localhost', '**********', '**********');
mysql_select_db('**********');
$sql = "SELECT Make FROM CarMakes";
$result = mysql_query($sql);
echo "<select name='carmake3'>";
echo "<option value='Make'>Make</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Make'] . "'>" . $row['Make'] .
"</option>";}
echo "</select>";
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('carmodel3').change(function() {
jQuery('carmake3').change();
});
});
</script>
<?php
mysql_connect('localhost', '**********', '**********');
mysql_select_db('**********');
$sql1 = "SELECT * FROM myTable WHERE Make='carmake3'";
$result1 = mysql_query($sql1);
echo "<select name='carmodel3'>";
echo "<option value='Model'>Model</option>";
while ($row = mysql_fetch_array($result1)) {
echo "<option value='" . $row['Model'] . "'>" . $row['Model'] .
"</option>";}
echo "</select>";
?>
<input type="text" maxlength="4" name="car3year" placeholder="year"
class="WriteInBox"/>
<input type="text" maxlength="6" name="car3miles" placeholder="miles"
class="WriteInBox"/>
</div>
</form>

No comments:

Post a Comment