472,976 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,976 software developers and data experts.

Using Javascript to rotate through web checkout shopping comparison surveys

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
6 3078

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
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
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
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
Thank you. It looks like the document.write command does the trick for
nested scripts.

Mar 2 '06 #6
Thank you Rob! I was able to get it to work with your awesome code.

Mar 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mobile.office | last post by:
Can you assist with a PHP shopping cart script. I need to call say MyShoppingCart with session ID Command say Change, Display, may not be necessary as assume no products means display...
2
by: OM | last post by:
I need a simple Javascript shopping cart. I did a few searches on Yahoo... And got a few results of free Javascript shopping carts. The problem is there tooo complicated and very hard to...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
5
by: nivas.meda | last post by:
Hi, I have an excel sheet with a graph and cells.If i change the value in the excel cells the graph will reflect.Now i am going to implement this functionality in html page.I successfully saved...
6
by: Alan Silver | last post by:
Hello, I have a page where users can alter the contents of a shopping basket. Once they are happy with the contents, they click a "checkout" button and are taken to the checkout page. What...
7
by: isaac2004 | last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart page i am having trouble generating 3 numbers; a subtotal, a shipping total, and a final price. here is my code i would...
1
by: ceolino | last post by:
Hi all. I have a simple default.aspx file where I declare a JavaScript function: <script type="text/javascript" language="JavaScript"> .... function rotate() { .... } </script>
1
by: jecha | last post by:
I'm implementing a shopping cart but am having a problem in checking out a person who has added item in his/her shopping busket.The code for the checkout.php script is given below <?...
0
by: service0043 | last post by:
Some bargain prices can be found on jewelry that is sold in bulk and at auction houses on the internet. While the condition of the items might be used, some fine jewelry pieces will be sold as new....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.