I have an ajax call on a page
<select name='category' style='display: inline' onchange="filterResults(this.value)">
<div id='listresults'></div>
This then populates another dropdown based on that selection.
How do I repeat tyhis so that I can have multiple dropdowns on the page
i.e.
<select name='category2' style='display: inline' onchange="filterResults(this.value)">
<div id='listresults'></div>
I ried duplicating the javascript above to create function filterResults2 then call it on the onchange but I get the error filterResults2 is not defined.
<select name='category' style='display: inline' onchange="filterResults(this.value)">
<div id='listresults'></div>
Code:
var xmlhttp
function filterResults(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="categorydropdown.asp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("listresults").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
This then populates another dropdown based on that selection.
How do I repeat tyhis so that I can have multiple dropdowns on the page
i.e.
<select name='category2' style='display: inline' onchange="filterResults(this.value)">
<div id='listresults'></div>
I ried duplicating the javascript above to create function filterResults2 then call it on the onchange but I get the error filterResults2 is not defined.