Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2008, 11:50 PM   PM User | #1
mdj101
New Coder

 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
mdj101 is an unknown quantity at this point
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!
mdj101 is offline   Reply With Quote
Old 02-21-2008, 02:44 AM   PM User | #2
mdj101
New Coder

 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
mdj101 is an unknown quantity at this point
mmmm, I starting to believe it will need to be re-written, any help would be much appreciated. i'm new to this
mdj101 is offline   Reply With Quote
Old 02-21-2008, 11:18 AM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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) : "";   
 }
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 02-21-2008 at 11:22 AM..
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:35 AM.


Advertisement
Log in to turn off these ads.