English 中文(简体)
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 ){
   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 : test2@gmail.com
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 );
document.body.style.cursor =  wait ;
document.location.href= /app/site/backend/setshipmeth.nl?c=659197&n=1&sc=4&sShipMeth=2035&sShipCarrier= +dropdown.value;
最佳回答

This was my solution:

var dropdown = document.getElementById( shippingcarrierselect ); document.body.style.cursor =  wait ; document.location.href= /app/site/backend/setshipmeth.nl?c=659197&n=1&sc=4&sShipMeth=2035&sShipCarrier= +dropdown.value;
问题回答

Your variable "i" is global. Also, you should store options.length in the variable. "i" might be set by some scripts which cause infinite loop.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签