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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Duplicating Script

    Hi All,

    I have the following code that im using in my shopping cart (VPASP) to pull the reviews into the product page. I want to also pull the tell a friend page in aswell.

    Code:
    <script language="javascript">
    var xmlHttp
    
    function showTellafriend(str)
    {
    if (str.length==0)
    { 
    document.getElementById("tellafriend").innerHTML=""
    return
    }
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
    return
    } 
    var url="shoptellafriend.asp"
    url=url+"?id="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    } 
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
    document.getElementById("tellafriend").innerHTML=xmlHttp.responseText 
    } 
    } 
    
    function GetXmlHttpObject()
    { 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
    objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
    } 
    
    showTellafriend("[catalogid]")
    </script>
    I can change the code and it pulls in the tell a friend fine, but i cant get it to do both, just one or the other.

    What do I need to change in each section of javascript so they are unique and will both work together?

    thanks in advance!

  • #2
    New Coder
    Join Date
    Feb 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mmmm, I starting to believe it will need to be re-written, any help would be much appreciated. i'm new to this

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    use simpler code, and break your tasks into pieces wrapped in functions.
    if nothing else, you can cut and paste the two variations into separate working chunks.
    i don't see the other functionality you are loking for, but here is some simpler code for you to edit into what you need.

    Code:
    function IO(U){//tiny sjax by dandavis
        var X=((!window.XMLHttpRequest)?new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest());
        X.open('GET',U,0);
        X.send('');	
        return X.responseText;
    }
    
    function showTellafriend(str){
        var url="shoptellafriend.asp?id="+  str  +"&sid="+Math.random()
          document.getElementById("tellafriend").innerHTML= str ? IO(url) : "";   
     }
    Last edited by rnd me; 02-21-2008 at 11:22 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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