...

View Full Version : combining two functions...



Alith7
07-21-2009, 04:51 PM
I have two functions right now that work great separately. I would like to combine them, but i'm not sure how. here is what I have:

function selCustContact(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="/scripts/updatecust.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=custContactChange;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

function custContactChange()
{
if (xmlhttp.readyState==4)
{
document.getElementById("custContact").innerHTML=xmlhttp.responseText;
}
}




function selSalesRep(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="/scripts/updaterep.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=custRepChange;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

function custRepChange()
{
if (xmlhttp.readyState==4)
{
document.getElementById("salesRep").innerHTML=xmlhttp.responseText;
}
}

I would like to run them both when I change a drop down menu, how do I do that? i'm sorry, I'm REALLY new to all this and trying to figure out some complex stuff as I go.

Thank you for your help in advance!

ckeyrouz
07-21-2009, 04:57 PM
try this:


<select id="zId" name="zName" onchange="selCustContact(params);selSalesRep(params)"></select>

Alith7
07-21-2009, 05:07 PM
ok, that's where i messed it up, i put a "," instead of ";"

Thank you!!

Alith7
07-21-2009, 05:14 PM
darn, not working.

Here is my select tag:

<select name="custName" tabindex="1" onchange="selCustContact(this.value);selSalesRep(this.value)">

When I run it, on Safari it ignores the "selCustContact" function and only process "selSalesRep". On FF it ignores the "selCustContact" function, but then process the return using the DIV ID for the contact instead of the SalesRep. any ideas?

Trinithis
07-21-2009, 05:33 PM
<select name="custName" tabindex="1" onchange="(function(self){selCustContact(self.value);selSalesRep(self.value)})(this)">

Alith7
07-21-2009, 05:46 PM
changed my mind

Alith7
07-21-2009, 05:56 PM
ok, figured it out. I was using the variable xmlhttp in BOTH functions so it was getting confused when processing the two functions together. I changed the "selSalesRep" functions to process the xmlhttp2 variable and everything works perfectly.

thank you for the help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum