javascript function won't stop looping - It's on a netsuite website

Posted by Lauren on Stack Overflow See other posts from Stack Overflow or by Lauren
Published on 2010-06-04T15:54:00Z Indexed on 2010/06/05 6:22 UTC
Read the original article Hit count: 477

Filed under:
|
|
|
|

I need to change the shipping carrier drop-down and shipping method radio button once via a javascript function, not forever.

However, when I use this function, which executes when on the Review and Submit page when the order is < $5, it goes into an endless loop:

function setFreeSampShipping(){
 var options = document.forms['checkout'].shippingcarrierselect.getElementsByTagName('option');
 for (i=0;i<options.length;i++){
  if (options[i].value == 'nonups'){
   document.forms['checkout'].shippingcarrierselect.value='nonups';
   document.forms['checkout'].shippingcarrierselect.onchange();
   document.location.href='/app/site/backend/setshipmeth.nl?c=659197&n=1&sc=4&sShipMeth=2035';
  }
 }
}

It gets called from within this part of the function setSampPolicyElems() which you can see I've commented out to stop the loop:

if (carTotl < 5 && hasSampp == 1) { 
    /*
    if (document.forms['checkout'].shippingcarrierselect.value =='ups'){
      setFreeSampShipping();
    }
    */
    document.getElementById('sampAdd').style.display="none";
    document.getElementById("custbody_ava_webshiptype").value = "7";//no charge free freight
    if (document.getElementById("applycoupon")) {
        document.location.href='/app/site/backend/setpromocode.nl?c=659197&n=1&sc=4&kReferralCode=SAMPLE'
    } 
    document.write("<div id='msg'><strong>Sample & Shipping:</strong></span> No Charge. (Your sample order is < $5.)</div>");
}

To see the issue, go to the order review and submit page here: https://checkout.netsuite.com/s.nl?c=659197&sc=4&n=1 (or go to http://www.avaline.com, hit "checkout", and login)

You can log in with these credentials: Email:[email protected] Pass:test03

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about function