|
Hello,
I have some script where I am using Javascript to pull some data from a .php page without the page reloading. I can get everything to work except I am trying to pass the variable thru the get method. Below is my code. I would like to replace variable 'Ford' in the onchange handle with one of the selected models. I don't quite know how to replace the variable 'Ford' with one of the selection options in the form before the 'fetchData' function is sent and retrieves the data I need from the dataPage.php script. Any help would be greatly appreciated.
<?
require_once('connections/dropdown.php');
// GET LIST OF MAKES FOR SELECTION LIST
//if(isset($_GET['year'])){
mysql_select_db($database_myConnection, $myConnection);
$query_RecordsetMake = "SELECT DISTINCT make FROM list ORDER BY make";
$RecordsetMake = mysql_query($query_RecordsetMake, $myConnection) or die(mysql_error());
$row_RecordsetMake = mysql_fetch_assoc($RecordsetMake);
$totalRows_RecordsetMake = mysql_num_rows($RecordsetMake);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function fetchData(url,objectID) {
var pageRequest = false;
if (window.XMLHttpRequest)pageRequest = new XMLHttpRequest();
else if (window.ActiveXObject) pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
else return false;
pageRequest.onreadystatechange = function() {
var object = document.getElementById(objectID);
object.innerHTML = pageRequest.responseText;
}
pageRequest.open('GET',url,true);
pageRequest.send(null);
}
</script>
</head>
<body>
<form action="" method="post" name="form1">
<select name="year" id="year">
<option value="" selected="selected">Step 1: Select Year</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
</select>
<!-- value="<? echo ""."?year=$_GET[year]&make=".$row_RecordsetMake['make']; ?>"-->
<!-- onchange="fetchData('dataPage.php?make=','message' ); return false;" -->
<select name="make" id="make" onchange="fetchData('dataPage.php?make=Ford', 'message'); return false;" >
<!-- <select name="make" id="make" onchange="jumpPage(this.form.make); return false;"> -->
<option selected="selected" value="">Step 2: Select Make</option>
<? if(isset($_GET['make'])) {
$myMake = "<option value=\"$_GET[make]\" selected=\"selected\">$_GET[make]</option>";
}
?>
<?php
do {
?>
<option value="<? echo "dataPage.php"."?make=".$row_RecordsetMake['make']; ?>"><?php echo $row_RecordsetMake['make']?></option>
<?php
} while ($row_RecordsetMake = mysql_fetch_assoc($RecordsetMake));
$rows = mysql_num_rows($RecordsetMake);
if($rows > 0) {
mysql_data_seek($RecordsetMake, 0);
$row_RecordsetMake = mysql_fetch_assoc($RecordsetMake);
}
?>
</select></td>
</form>
<div id="message"></div>
</body>
</html>
|