Ajax Search as You Type issue
Hi, I posted this question on another forum but haven't had any replies, so I figured I would ask here, as I got some great help with my other issues here.
I have an Ajax script that filters results onKeyUp, but it does not work for me in IE (I've just tried using IE 8, haven't tried others yet). It works fine in Firefox. The thing is, I'm using a very similar script for another search as you type Ajax update filter, which works in both Firefox and IE. I'm not sure is there something wrong with my script, or just my IE isn't working properly. Here is the code for it:
Javascript
Code:
<script language="javascript" type="text/javascript">
function ajaxListSearchSpecialFunction(s){
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;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var SearchListDisplay = document.getElementById('searchspeciallist');
SearchListDisplay.innerHTML = ajaxRequest.responseText;
}
}
var s = document.getElementById('specialsearchbox').value;
var queryString = "?s=" + s + "&categoryid=<?php echo $categoryid;?>";
ajaxRequest.open("GET", "searchspeciallist.php" + queryString, true);
ajaxRequest.send(null);
}
</script>
The Search As You Type Form
Code:
<form name="listfilterspecialform" method="get">
<input type="hidden" name="categoryid" value="<?php echo $categoryid;?>">
<input class="largesearch" type="text" id="specialsearchbox" autocomplete="off"
value="<?php if(isset($_GET['s']))
{echo $_GET['s'];}
else {echo "Search Airlines";}?>"
name="s" onfocus="if(this.value=='Search Airlines')this.value='';"
onblur="if(this.value=='')this.value='Search Airlines';" onkeyup="ajaxListSearchSpecialFunction('');"/>
</form>
The part of the page that is meant to be updating
Code:
<tbody id="searchspeciallist">
<?php include "searchspeciallist.php"?>
</tbody>
I know it's not an issue with searchspeciallist.php, because when the form is submitted manually, by pressing enter and the page reloading, the results are filtered the way they should be, so I'm guessing it must besomething to do with the javascript. The thing is, I'm using the same script for a search as you type on another part of the same page, which is working fine.
If you want to test it out, an example of it can be found over here:
http://www.airline-luggage-regulatio...s&categoryid=1
The Search as you Type field in the left column is working. It's the one in the main column (large "Search Airlines" input field as you scroll down a few cm), which is meant to filter the table shown below it, is the one that is not working. Is it just me that it's not working for, or an issue with the code not working for anyone using IE? Chrome and Firefox both work flawlessly.
Thanks a lot,
Tom