开发者

Do If statements stop code after it being executed?

I have an order form script with a function in which says if the job will take longer than x flash up a message. Script works fine if i leave my if statement out, but If i put it in it only executes if X variable meets the if condition, does this make sense?

My Script is...

if (EstimatedCoreHours >= 50000)
   {
   document.getElementById("AccountManagement").innerHTML='You have a big Job on your hands - Contact Us!';
   document.getElementById("AccountManagement").style.backgroundColor="yellow";
   }
   else
   {
   document.getElementById("AccountManagement").innerHTML=''; 
   document.getElementById("ContBtn").style.display="";
   }

   if (EstimatedCoreHours >= 100000)
   {
   document.getElementById("LeadTimes").innerHTML='5 Business Days!';
   document.getElementById("LeadTimes").style.backgroundColor="yellow";
   }
   else if (EstimatedCoreHo开发者_C百科urs >=25000)
   {
   document.getElementById("LeadTimes").innerHTML='2 Days';  
   document.getElementById("LeadTimes").style.backgroundColor="yellow";
   }
   else
   {
   document.getElementById("LeadTimes").innerHTML='Right Away'; 
   document.getElementById("LeadTimes").style.backgroundColor="yellow";  
   }


If statements will not stop execution. Execution stops when the interpreter encounters an error in the code. Check whether the variable used inside the if is defined.


You've got a mix of ifs and else-ifs here and the indents are wrong. If EstimatedCoreHours is say 150,000 then the first two ifs will both fire. Did you mean them to be nested?

One last point, the criteria run 50,000, 100,000, 25,000. Are you deliberately testing the values out of order or is there a typo here?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜