Combining both function help needed?

function showUser25(str1)
{
if (str1=="")
{
document.getElementById("words").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("words").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("GET","wordCount.php?p="+str1,true);
xmlhttp.send();
}
function showUser26(str1)
{
if (str1=="")
{
document.getElementById("orderprice").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("orderprice").innerHTML=xm lhttp.responseText;
}
}
xmlhttp.open("GET","wordCalculate.php?p="+str1,tru e);
xmlhttp.send();
}

I want to combine both these functions please help so that i can call only one function at onchange or onKeyUp

Are you asking to combine these two (which look to be working off of two totally different fields), or making this more generic?

If it’s combining the two, that seems like a REALLY bad idea unless you have a real good reason for doing it. If it’s to make it more generic, then that’s not that hard to do.

yeah i need to combine both of these as i need to call both these functions in onKeyUp event. Calling both of these at same time not working so its better that if i can combine both of them. Any help please.

you can call both function on a single keyup event …

tries but its not working, both working seperately but if m using it like onKeyUp=“showUser25(this.value);showUser26(this.value);” its not working

that’s because xmlhttp is a global variable and thus the second function overwrites it.

so whats the solution then?

It sounds like the solution is to use two different variables for xmlhttp, such as xmlhttp1 and xmlhttp2

using local variables would be the most simple approach.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.