I'm building a form that uses ajax to populate a list of tafes (educational institutes) based on which state (in Australia) you select. The form uses GET to get the information from ajax and POST to post the information to the next page. And after 3 hours of trying to figure out why it doesn't work, I'm turning to you guys for help! Basically, the ajax works, as in the select box shows up when I select a state, however, when I post it, all information other than the select box gets posted.
***** PLEASE USE THE
Code: Select all
TAG WHEN POSTING *****[/color]
Here's some code:
form start:Code: Select all
<form action="register.php" method = "post" enctype="multipart/form-data"> Code: Select all
<?
echo "<script language=\"javascript\" type=\"text/javascript\">
<!--
//Browser Support Code
function ajaxFunction(selected){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject(\"Msxml2.XMLHTTP\");
} catch (e) {
try{
ajaxRequest = new ActiveXObject(\"Microsoft.XMLHTTP\");
} catch (e){
// Something went wrong
alert(\"Your browser broke!\");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var fac1 = selected.selectedIndex;
var face = selected[fac1].text;
ajaxRequest.open(\"GET\", \"showtafe.php?fac=\" + face, true);
ajaxRequest.send(null);
}
//-->
</script>";
?>Code: Select all
<? echo "<select name=\"state\" id=\"state\" onChange=\"ajaxFunction(this);\">"; ?>
<option value="Select" selected>Select</option>
<option value="ACT">ACT</option>
<option value="NSW">NSW</option>
<option value="NSW">NT</option>
<option value="NSW">QLD</option>
<option value="NSW">SA</option>
<option value="NSW">TAS</option>
<option value="NSW">VIC</option>
<option value="NSW">WA</option>
</option>
</select>Code: Select all
<?
include 'db.php';
$faculty = $_GET['fac'];
$faculty = mysql_real_escape_string($faculty);
$findfac = mysql_query("SELECT * FROM tafes where state = '$faculty' order by tafe_name ")
or die(mysql_error());
//$findfac2 = mysql_fetch_array($findfac);
if (($faculty != "All") && ($faculty != "Select")){
echo "<select name=\"tafes\">";
while($row = mysql_fetch_assoc($findfac))
{
echo "<option value=$row[tafe_id]>$row[tafe_name]</option>";
}
echo "</select><br>";
}else if ($faculty == "Select") {
echo "Please select a state first";
}
?>then back in my original form I have:
Code: Select all
echo "<div id='ajaxDiv'>The Relevant TAFEs will display here</div>";_______
And that's it. I'm worried that possibly inserting into the middle of a post form won't work? But I can't find any mention of that thus far. With all the other Ajax I've done (including reusing the above code) I've been using forms that submit data via GET, and this makes me think this might be part of the problem. I'd really appreciate any response
Simon