Lauren Lauren - 1 year ago 64
Javascript Question

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

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'){

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'){
document.getElementById("custbody_ava_webshiptype").value = "7";//no charge free freight
if (document.getElementById("applycoupon")) {
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: (or go to, hit "checkout", and login)

You can log in with these credentials:

Email :

Pass : test03

My solution so far was to swap out the onchange() event trigger line with this, since then I'm not running document.location.href twice: instead, I'm passing the two variables in the one URL query string:

var dropdown = document.getElementById('shippingcarrierselect'); = 'wait';

Answer Source

This was my solution:

var dropdown = document.getElementById('shippingcarrierselect'); = 'wait'; document.location.href='/app/site/backend/'+dropdown.value;