dolythgoe
asked on
AJAX building query string from checkbox array
Hi all,
I'm trying to build a querystring from a check box array.
Here's my AJAX code - the var options and var querystring are the areas I'm guessing I need to flesh out but not quite sure how to do it:
Here's some checkboxes:
There can be loads of these and I was thinking of sending the string of id's to the server like:
filter_option=1-2-3-4-5-45 -34-67-89 and doing an explode() on them before querying.
Lastly, the user arrives at this page with variables in the URL obtained via GET already.
e.g. search.php?qs=My+Search&da te=3m
So I have a few questions around this:
A) How can this be achieved?
B) Is this the best way and is this fully browser compliant?
C) How can I include the variables already in the URL in the AJAX call? Write them into it via php?
Huge thanks
David
I'm trying to build a querystring from a check box array.
Here's my AJAX code - the var options and var querystring are the areas I'm guessing I need to flesh out but not quite sure how to do it:
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
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){
document.getElementById('result').innerHTML = ajaxRequest.responseText;
}
}
//Need to grab query string and append checked checkboxes array
var options = document.get......
var queryString = "?filter_options=" + options....;
ajaxRequest.open("GET", "filter_query.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
Here's some checkboxes:
<label for="1"><input type="checkbox" onClick="ajaxFunction();" name="filter_option[]" value="1" id="1">Option 1</label>
<label for="2"><input type="checkbox" onClick="ajaxFunction();" name="filter_option[]" value="2" id="2">Option 2</label>
<label for="3"><input type="checkbox" onClick="ajaxFunction();" name="filter_option[]" value="3" id="3">Option 3</label>
There can be loads of these and I was thinking of sending the string of id's to the server like:
filter_option=1-2-3-4-5-45
Lastly, the user arrives at this page with variables in the URL obtained via GET already.
e.g. search.php?qs=My+Search&da
So I have a few questions around this:
A) How can this be achieved?
B) Is this the best way and is this fully browser compliant?
C) How can I include the variables already in the URL in the AJAX call? Write them into it via php?
Huge thanks
David
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER