Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts

    combining two functions...

    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:
    Code:
    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;
    	}
    }
    Code:
    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!
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    try this:

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

  • Users who have thanked ckeyrouz for this post:

    Alith7 (07-21-2009)

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    ok, that's where i messed it up, i put a "," instead of ";"

    Thank you!!
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #4
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    darn, not working.

    Here is my select tag:
    Code:
    <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?
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #5
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    Code:
    <select name="custName" tabindex="1" onchange="(function(self){selCustContact(self.value);selSalesRep(self.value)})(this)">
    Trinithis

  • #6
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    changed my mind
    Last edited by Alith7; 07-21-2009 at 06:56 PM.
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #7
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    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!
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •