I have two items first is a dropdownbox that once user selects its options will trigger a javascript code and show the results on the same page,
the second one is a input box and a search button, once user type something and click on search button, it triggers the javascript but for some reasons it adds the value to the current page address rather than redirecting to other page and xmlhttp.status returns 0.
Rather than redirecting to class/myresults.php it add the item1 and its value to the current page address which is www.myexample.com/index.php?item1=computer
My form that does not work
<form action="">
<input name="search" type="text" title="Search"/>
<input type="submit" value="search" onclick="finditem(this.form.search.value)"/>
</form>
function finditem(option){
alert(option); <<<<shows the correct entered value
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
alert(xmlhttp.status); << returns 0
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("Result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","class/myresults.php?item1="+option,true);
xmlhttp.send();
}
java script of the drop down box that works
<select name="items" onchange="findbox(this.value)">
.....
</select>
function findbox(option){
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("Result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","class/myresults.php?item2="+option,true);
xmlhttp.send();
}