Reply
Passing a variable with Javascript
Old 09-19-2008, 07:07 PM Passing a variable with Javascript
Average Talker

Posts: 15
Trades: 0
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>
macbaby is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 09-19-2008, 07:24 PM Re: Passing a variable with Javascript
Average Talker

Posts: 15
Trades: 0
I'm also noticing in my code that when the page retrieves the information (ie: all of the Ford models) from the dataPage.php that it is not listing on my current page in the code, even though it shows in the browser. Does this mean my 'model' selection field doesn't exist in the form? I need to retrieve the model line for the particular manufacturer and after the client selects their make and model I need to make sure it gets passed in the form when they submit it. Hope that makes sense. If you need more info let me know and I'll try to explain better. Here is link to the page I am testing on: http://www.autoloansnw.com/dataTest.php
Thanks.
macbaby is offline
Reply With Quote
View Public Profile
 
Old 09-22-2008, 09:29 PM Re: Passing a variable with Javascript
Average Talker

Posts: 15
Trades: 0
Nevermind. I figured it out on my own.
macbaby is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Passing a variable with Javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10123 seconds with 13 queries