PDA

View Full Version : Duplicating Script


mdj101
02-20-2008, 11:50 PM
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.


<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!

mdj101
02-21-2008, 02:44 AM
mmmm, I starting to believe it will need to be re-written, any help would be much appreciated. i'm new to this

rnd me
02-21-2008, 11:18 AM
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.


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) : "";
}