I’m trying to call the same Ajax get PHP from two different elements Onclick. The second one isn’t working.
Index.js
function getproduct(p){
if(p==' '){
document.getElementById('f1').innerHTML=' ';
}
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('f1').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open('GET','getproduct.php?q='+p,true);
xmlhttp.send();
}//the function I'm trying to call from two different Onclicks
var products=new Array();
var sidebarli=document.getElementById('sidebar').getElementsByTagName('li');
for(i=0;i<sidebarli.length;i++){
if(sidebarli[i].className=='item' && sidebarli[i].parentNode.className=='prod'){
sidebarli[i].onclick=function(){
EvalSound1();
var p=this.id;
alert(p+': Is sending your request.');
products.push(p);
getproduct(p);
document.getElementById('logo').className=p;
f1.className='product';
document.getElementById('blank').src='scripts/product.js';
hidewelcome();
};
}//function works
var breturn=document.getElementById('breturn');
addEvent(breturn,'click',function(){
var p=document.getElementById('productreturn').value;
alert('Getting product: '+p);
getproduct(p);
f1prompt.style.display='none';
EvalSound2();
},false);//function doesn't work????????
Any help greatly appreciated:p