By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Using Javascript to rotate through web checkout shopping comparison surveys

P: n/a
Hello,

I am trying to get my website checkout page to rotate / take turns
displaying shopping comparison engine surveys rather than display them
all 4 at the same time, thus overwhelming & annoying the customer.

I tried to put together some code to rotate through a Bizrate,
PriceGrabber, Shopping.com and Nextag survey, I have taken the survey
code the shopping comparison engines gave and tried to put it in a
random number script to make them rotate. I have replaced our account
numbers with asterisks below. Being new to javascript, I obviously
have some major syntax errors or something. Would anyone be so kind
and friendly as to show me what I need to change on this code to get it
to work?

<SCRIPT language="JavaScript">
<!-- Reviews Code
var rand = Math.random();
if(rand < 0.25)

<!-- BEGIN: BizRate Survey Invitation HTML -->
<script language="JavaScript"
src="https://eval.bizrate.com/js/pos_*****.js"
type="text/javascript"></script>
<!-- END: BizRate Survey Invitation HTML -->

else

if(rand < 0.5)

<!-- PriceGrabber Merchant Evaluation Code --> <script
language="javascript" type="text/javascript"><!-- popup_pos_x=200;
popup_pos_y=20; popup_title_color = "#000080"; popup_title_font_color =
"#FFFFFF"; //--> </script> <script language="javascript"
src="https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=****"
type="text/javascript"></script>
<NOSCRIPT>
<A
href="https://www.pricegrabber.com/rating_merchrevpop.php?retid=****"
target=_blank>
<img src="https://images.pricegrabber.com/images/rating_merchpopup.gif"

border="0" width="480" height="166" alt="Merchant
Evaluation"></A></NOSCRIPT>
<!-- End PriceGrabber Code -->

else

if(rand < 0.75)

<iframe width="0" height="0"
src="https://merchants.nextag.com/seller/review/popup.jsp?id=*******"></iframe>

else

<script language="JavaScript"

src="https://www.shopping.com/xMerchantSurvey.js?pt=js&direct=1&mid=******">

</script>
// -->
</SCRIPT>
Thanks in advance!
Shawn

Feb 27 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

s...@competitiveedgeproducts.com wrote:
Hello,

I am trying to get my website checkout page to rotate / take turns
displaying shopping comparison engine surveys rather than display them
all 4 at the same time, thus overwhelming & annoying the customer.

I tried to put together some code to rotate through a Bizrate,
PriceGrabber, Shopping.com and Nextag survey, I have taken the survey
code the shopping comparison engines gave and tried to put it in a
random number script to make them rotate. I have replaced our account
numbers with asterisks below. Being new to javascript, I obviously
have some major syntax errors or something. Would anyone be so kind
and friendly as to show me what I need to change on this code to get it
to work? From just skimming at the code, you'll be going through a lot of edits. Let's see if we can do some incremental changes til we reach the goal
we want. :)
<SCRIPT language="JavaScript">
The language attribute is deprecated, use the type attribute instead:

<script type = "text/javascript">
<!-- Reviews Code
HTML comment delimiters are unnecessary. If you want to comment, why
not just use javascript comment delimiters:

//reviews code
<!-- BEGIN: BizRate Survey Invitation HTML -->
Remove HTML comment delimiters.
<script language="JavaScript"
src="https://eval.bizrate.com/js/pos_*****.js"
type="text/javascript"></script>
Problem: You cannot have nested scripts.
<!-- END: BizRate Survey Invitation HTML -->
Remove HTML comment delimiters
<!-- PriceGrabber Merchant Evaluation Code --> <script
language="javascript" type="text/javascript"><!-- popup_pos_x=200;
popup_pos_y=20; popup_title_color = "#000080"; popup_title_font_color =
"#FFFFFF"; //--> </script> <script language="javascript"
src="https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=****"
type="text/javascript"></script>
Remove HTML comment delimiters and move the script tag outside.
<NOSCRIPT>
<A
href="https://www.pricegrabber.com/rating_merchrevpop.php?retid=****"
target=_blank>
<img src="https://images.pricegrabber.com/images/rating_merchpopup.gif"

border="0" width="480" height="166" alt="Merchant
Evaluation"></A></NOSCRIPT>
Problem: You are now mixing javascript code with HTML. HTML code is
separate from javascript.
<!-- End PriceGrabber Code -->
Remove HTML comment delimiter.
if(rand < 0.75)

<iframe width="0" height="0"
src="https://merchants.nextag.com/seller/review/popup.jsp?id=*******"></iframe>
Problem: Mixing HTML and javascript code again.
<script language="JavaScript"

src="https://www.shopping.com/xMerchantSurvey.js?pt=js&direct=1&mid=******">

</script>
Problem: another nested script.
// -->


Finally, remove the above as well. This will be our first step to
getting to your goal. After you have cleaned up the code above, post
the new changes and we can proceed from there.

Feb 27 '06 #2

P: n/a
sa***@competitiveedgeproducts.com wrote:
Hello,

I am trying to get my website checkout page to rotate / take turns
displaying shopping comparison engine surveys rather than display them
all 4 at the same time, thus overwhelming & annoying the customer.

I tried to put together some code to rotate through a Bizrate,
PriceGrabber, Shopping.com and Nextag survey, I have taken the survey
code the shopping comparison engines gave and tried to put it in a
random number script to make them rotate. I have replaced our account
numbers with asterisks below. Being new to javascript, I obviously
have some major syntax errors or something. Would anyone be so kind
and friendly as to show me what I need to change on this code to get it
to work?

<SCRIPT language="JavaScript">
The language attribute is deprecated, type is required

<script type="text/javascript">

<!-- Reviews Code
Do not use HTML style comment delimiters inside script elements, ever.
They server no useful purpose and are potentially harmful. Most
browsers will tolerate them before any real script is encountered, but
placed anywhere else in the script they will almost certainly cause
problems...

var rand = Math.random();
if(rand < 0.25)

<!-- BEGIN: BizRate Survey Invitation HTML -->
Like here.

<script language="JavaScript"
src="https://eval.bizrate.com/js/pos_*****.js"
type="text/javascript"></script>
You can't nest script elements...

<!-- END: BizRate Survey Invitation HTML -->
Or put HTML style comments inside scripts...

else

if(rand < 0.5)

<!-- PriceGrabber Merchant Evaluation Code --> <script
language="javascript" type="text/javascript"><!-- popup_pos_x=200;
popup_pos_y=20; popup_title_color = "#000080"; popup_title_font_color =
"#FFFFFF"; //--> </script> <script language="javascript"
src="https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=****"
type="text/javascript"></script>
<NOSCRIPT>
<A
href="https://www.pricegrabber.com/rating_merchrevpop.php?retid=****"
target=_blank>
<img src="https://images.pricegrabber.com/images/rating_merchpopup.gif"

border="0" width="480" height="166" alt="Merchant
Evaluation"></A></NOSCRIPT>
<!-- End PriceGrabber Code -->

else

if(rand < 0.75)

<iframe width="0" height="0"
src="https://merchants.nextag.com/seller/review/popup.jsp?id=*******"></iframe>

else

<script language="JavaScript"

src="https://www.shopping.com/xMerchantSurvey.js?pt=js&direct=1&mid=******">

</script>
// -->
</SCRIPT>


It seems that you want to randomly insert a script element into the
page. I'd suggest Using an array to store the script element URLs,
generate a random number within the range of the length of the array and
use that to randomise the URL.

e.g.

<script type="text/javascript">

// Put URLs in here
var urlArray = [
'https://eval.bizrate.com/...',
'https://www.pricegrabber.com/...',
'https://merchants.nextag.com/...'
];

// Now randomly select one to use in the script element
// added to the page
var randURL = Math.floor(urlArray.length*Math.random());

document.write('<script type="text/javascript" src="'
+ randURL + '"><\/script>');
</script>
Now to add more comparison sites, just add their URL to the array. The
script element added by the document.write is actually added immediately
after the above script element, it is not nested inside it.
--
Rob
Feb 27 '06 #3

P: n/a
Thanks Rob,

I tried the array code, however it didn't do anything. It seems like
the randURL is just generating a number rather that representing the
string url value. Is there something else I need? The other problem is
that the bizrate url is to a javascript and when it is launched in the
browser as this "https://eval.bizrate.com/js/pos_*****.js" instead of
as a script like below - it displays a bunch of nasty code. I think
they did it as a javascript so that the popup blockers would not block
it erroneously.

<!-- BEGIN: BizRate Survey Invitation HTML -->
<script language="JavaScript"
src="https://eval.bizrate.com/js/pos_*****.js"
type="text/javascript"></script>
<!-- END: BizRate Survey Invitation HTML -->

Thanks,
Shawn

Feb 28 '06 #4

P: n/a
sa***@competitiveedgeproducts.com wrote:
Thanks Rob,

I tried the array code, however it didn't do anything. It seems like
the randURL is just generating a number rather that representing the
string url value. Is there something else I need?
Yes, code that works! Replace the following line:

var randURL = Math.floor(urlArray.length*Math.random());
with:

var randURL = urlArray[Math.floor(urlArray.length*Math.random())];

The other problem is
that the bizrate url is to a javascript and when it is launched in the
browser as this "https://eval.bizrate.com/js/pos_*****.js" instead of
as a script like below - it displays a bunch of nasty code. I think
they did it as a javascript so that the popup blockers would not block
it erroneously.


I don't want to have anything to do with testing the URLs. My intention
was to show how to put a random element into a page using document.write().

The values of the elements of the array should be strings that when
written to the document create valid HTML. I'll change the name to
htmlArray since that's what's in there.

For example, to write exactly what you had in your first post, declare
the array as:

// Initialise array
var htmlArray = [];

// BizRate element
htmlArray[0] = '<!-- BEGIN: BizRate Survey Invitation HTML -->'
+ '<script type="text/javascript" '
+ 'src="https://eval.bizrate.com/js/pos_*****.js"'
+ '><\/script>'
+ '<!-- END: BizRate Survey Invitation HTML -->';

// PriceGrabber element
htmlArray[1] = '<!-- PriceGrabber Merchant Evaluation Code -->'
+ '<script type="text/javascript">'
+ 'var popup_pos_x=200;'
+ 'var popup_pos_y=20;'
+ 'var popup_title_color="#000080";'
+ 'var popup_title_font_color="#FFFFFF";'
+ '<\/script>'
+ '<script type="text/javascript"'
+ 'src="https://www.pricegrabber.com/'
+ 'rating_merchrevpopjs.php?retid=****"'
+ '><\/script>'
+ '<!-- End PriceGrabber Code -->';
There seems little point in using script to write a no script element.
Add more as appropriate, then...

// Randomly select one to write to the page
var randHTML = htmlArray[Math.floor(htmlArray.length*Math.random())];

document.write(randHTML);
You will have a bunch of HTML in your page that may never get used -
maybe that's not a problem.
--
Rob
Mar 1 '06 #5

P: n/a
Thank you. It looks like the document.write command does the trick for
nested scripts.

Mar 2 '06 #6

P: n/a
Thank you Rob! I was able to get it to work with your awesome code.

Mar 2 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.