Using Javascript to rotate through web checkout shopping comparison surveys

Discussion in 'Javascript' started by sales@competitiveedgeproducts.com, Feb 27, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. web.dev Guest

    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.
    web.dev, Feb 27, 2006
    #2
    1. Advertising

  3. RobG Guest

    Re: Using Javascript to rotate through web checkout shopping comparisonsurveys

    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
    RobG, Feb 27, 2006
    #3
  4. Guest

    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, 2006
    #4
  5. RobG Guest

    Re: Using Javascript to rotate through web checkout shopping comparisonsurveys

    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
    RobG, Mar 1, 2006
    #5
  6. Guest

    Thank you. It looks like the document.write command does the trick for
    nested scripts.
    , Mar 2, 2006
    #6
  7. Guest

    Thank you Rob! I was able to get it to work with your awesome code.
    , Mar 2, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Franks

    Sample demonstrating how to create surveys?

    Steve Franks, Jun 4, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    498
    Online Survey Diva
    Jun 18, 2004
  2. Dmitry Duginov

    DNN custom module for surveys

    Dmitry Duginov, Oct 29, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    369
    Steven Cheng[MSFT]
    Nov 17, 2004
  3. RC
    Replies:
    1
    Views:
    863
    Bjoern Hoehrmann
    Aug 3, 2006
  4. IanJSparks
    Replies:
    0
    Views:
    1,132
    IanJSparks
    Jan 10, 2008
  5. Sura
    Replies:
    3
    Views:
    643
    -TNO-
    Aug 14, 2009
Loading...

Share This Page