Hi Everyone.
I’ve recently begun using AJAX on my website and have ran into a problem. Hopefully not a massive one and with your help i’ll be on my way ?
My webpage: [B]catalogue.php
I now want to implement a drop-down box to sort by price, name, newest etc…
I have tested the AJAX out with a dropdown box for changing the category and it works fine, this is because it is only passing one variable which it gets via the javascript “this.value”.
The sort by price box requires two variables to be passed and its here i’m pulling my hair out.
I can pass the “this.value” which tells the javascript function I want to sort by price/newest/etc but I cannot figure out how to pass the category variable ($cid) so that when the xmlhttp.open calls the url: getSort.php it passes both pieces of info.
If anyone can help I would be most grateful.
My javascript is:
[CODE]function showSort(str)
{
var cat = <?php echo $cid ?>;
if (str==””)
{
document.getElementById(“txtHint”).innerHTML=””;
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”getSort.php?s=”+str,true);
xmlhttp.send();
}
The webpage dropdown box:
[code=php] <$php $cid = $_GET[‘cid’]; ?>
<select name=”sort” onchange=”showSort(this.value)”>
<option value=”pr-a”> Price (low-high) </option>
<option value=”pr-d”> Price (high-low) </option>
<option value=”nm”> Name (A-Z) </option>
</select>
<div id=”txtHint” style=”margin-top:-30px;”>