I think I'm just having one of those weeks where whatever I try to get this work simply does not work. At one stage I did not think that I was far off solving this problem, but now I feel as if I'm further away from the solution.
I'm simply trying to populate a second dropdown menu based on input from the first. The complicated part is that the SQL query returns the values as A,B,C and I look to explode them (stripping the ,) as A B C (each being an option in my next dropdown menu).
I have made my query work but I am struggling with the post and AJax call in my php file
Here's my code:
my.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#brigade').change(function() {
var t2choice = $('#t2choice').attr('value');
var t3choice = $('#t3choice').val()
$.ajax({
type: "POST",
url: "ajax.php",
data: "t2choice="+ t2choice,
success: function(){
$('form#submit').hide(function(){$('div.success').fadeIn();});
}
});
});
</script>
<?php
print ("<br /><center><font size='+1'><a href='/adm/main.php'>Main</a> - Select ".$t2name."</font>");
print ("<form method='post' action='' name='t2Form'>");
print ("<br /><br /><select id='t2choice' name='t2choice' value='".$t2name."' onChange='return BrigadeListOnChange()'>'");
print ("<option value='chooseOption'>Select a ".$t2name." to...</option>");
print ("</select>");
print ("<select id='t3choice' name='t3choice'");
print ("<option>Select t3</option>");
print ("<input type='hidden' name='form' value='showt5objects'>");
print (" <input type='submit' name='submit' value='Edit ".$t5name."s'>");
print (" OR <input type='submit' name='submit' value='Add New'>");
print ("<br /><br /><a href='javascript:history.go(-1)'>Cancel</a>");
print ("</form>");
?>
ajax.php
<html>
<?php $t2=$_GET["t2choice"];
echo $t2;
//DB Connection
(mySQL connect information is here and confirmed working - no issues here)
//--------------------------------------------------------------------------------//
$t3_query = "SELECT tier3_short_names FROM tgdata_tier2 WHERE tier2_short_name = '" . $t2 . "' ORDER BY tier2_short_name ASC"; // query
$t3_result = mysql_query($bde_query); ?>
<select name="t3choice">
<option>Select t3</option>
<?
while ($t3_row = mysql_fetch_array($t3_result, MYSQL_ASSOC)) {
foreach ( explode( ',', $t3_row['tier3_short_names']) as $item)
echo '<option value="', $item, '">', $item,'</option>';
// while($row=mysql_fetch_array($t3_result)) {
}
echo '</select></html>';
?>
The ajax file works when I manually route to ajax.php?t2choice=value - but I cannot get the second dropdown in my.php working :(
Any help would be greatly appreciated :)