milo3169
Programmer
- May 2, 2007
- 42
Hi,
I am a Newbie to AJAX and I'm not really sure if this is an AJAX question, but in this AJAX script I'm using I'm having problems passing a Dropdown list value to a serverpage url in AJAX.
I have this AJAX script where when someone selects a selection from a dropdown list it sends a request to a PHP file to create another dropdown list with specific information relating the first selection that was made. The functionality seems to be working and if I hard code the URL it works like I want it to.
The problem is that in that function call where it says...sub_cat_menu.php?item_code=wint,, I need to have "wint" as a dynamic variable that I can pass to the AJAX function. I think the problem is on where that the function call is on the SELECT field.
Below is the HTML Dropdown and function call
Is there a way that I can change that variable to what ever is selected from that dropdown list so it can be passed to the AJAX function? If so how do you do that?
I am a Newbie to AJAX and I'm not really sure if this is an AJAX question, but in this AJAX script I'm using I'm having problems passing a Dropdown list value to a serverpage url in AJAX.
I have this AJAX script where when someone selects a selection from a dropdown list it sends a request to a PHP file to create another dropdown list with specific information relating the first selection that was made. The functionality seems to be working and if I hard code the URL it works like I want it to.
Code:
<select class="formfield" name="item_code" onchange="makerequest('[COLOR=red]sub_cat_menu.php?item_code=wint[/color]','hw');">
Code:
<html>
<head>
<script type="text/javascript">
<!--
//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;
//Check if we are using IE.
try {
//If the Javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
//alert ("You are using Microsoft Internet Explorer.");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using Internet Explorer.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//alert ("You are using Microsoft Internet Explorder");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
alert ("You are not using Microsoft Internet Explorer");
}
function makerequest(serverPage, objID) {
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
//-->
</script>
</head>
Below is the HTML Dropdown and function call
Code:
<select class="formfield" name="item_code" onchange="makerequest('sub_cat_menu.php?item_code=wint','hw');">
<option selected value=""></option>
<?php echo build_dropdown(); ?>
</select>
Is there a way that I can change that variable to what ever is selected from that dropdown list so it can be passed to the AJAX function? If so how do you do that?