| | |
Javascript - how to stop/halt/break this loop/script plss
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2004
Posts: 2
Reputation:
Solved Threads: 0
Hi,
I'm a newbie on javascript, and am experimenting with this simple script below.
I was wondering how could I halt/quite/close the script/program after pressing the X or CANCEL button?
I try to press X and CANCEL button, but it won't quit and this script results in infinite loop
Pleaseee helppp...
I'm a newbie on javascript, and am experimenting with this simple script below.
I was wondering how could I halt/quite/close the script/program after pressing the X or CANCEL button?
I try to press X and CANCEL button, but it won't quit and this script results in infinite loop
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html><head><title>Phone Cost</title></head> <body on> <script> var i var minutes var monthly var excess var charge var total while (minutes=1) { minutes = prompt("Minutes Used:"); alert("Your entery was: "+minutes+""); monthly=40 excess=minutes-600 charge=excess*0.49 total=monthly+charge if(minutes>=600) { document.write("Your Minutes Uses is: "+minutes+" <br>"); document.write("Excess Minutes Uses is: "+excess+" <br>"); document.write("Monthly Charges is: $"+monthly+".00<br>"); document.write("Excess Minutes Charge is: "+charge+" <br>"); document.write("Total Charge is: "+total+" <br><br><br>"); } else { document.write("Your Minutes Uses is: "+minutes+" <br>"); document.write("Monthly Charges is: $"+monthly+".00<br><br><br>"); } } </script> </body> </html>
Pleaseee helppp...
•
•
•
•
Problem #1 if (minutes = 1) should be if (minutes ==1). You want to check the value of minutes using the == operator. I'm not sure what the = will do in JavaScript, but it is probably checking to see if minutes is a declared variable and returns true since it is.
what code are u using for cancel button. have u used close() function.
wait, the <script> tag doesnt have all the necessary attributes also:
for javascript it must be
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript">.....</script>
Last edited by vishesh; Dec 4th, 2006 at 9:35 am.
create a public/global variable called "stopped", set it to false when you start the loop.
inside the loop put:
then when you press "cancel" set the stopped variable to true.
inside the loop put:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
if(stopped){ break; }
Plato forgot the nullahedron..
I took a look at your code, and made a few adjustments. Do you see why this works vs. your code?
javascript Syntax (Toggle Plain Text)
<script type="text/javascript" lang="javascript"> var i; var minutes = 0; var monthly; var excess; var charge; var total; while (minutes != null) { minutes = prompt("Minutes Used:"); alert("Your entry was: " + minutes); monthly = 40; excess = minutes - 600; charge = excess * 0.49; total = monthly + charge; if (minutes >= 600) { document.write("Your Minutes Uses is: " + minutes + "<br>"); document.write("Excess Minutes Uses is: " + excess + "<br>"); document.write("Monthly Charges is: $" + monthly + ".00<br>"); document.write("Excess Minutes Charge is: " + charge + "<br>"); document.write("Total Charge is: " + total + "<br><br><br>"); } else { document.write("Your Minutes Use is: " + minutes + "<br>"); document.write("Monthly Charge is: $" + monthly + ".00<br><br><br>"); } } </script>
![]() |
Similar Threads
- Any keyword to break or continue a LOOP like as in C "break","continue" keawords?? (PHP)
- How could I break an infinite loop?? (Assembly)
- How do you Terminate an Infinite Loop? Impossible!!! (C++)
- How to call a ServerSide Script through Javascript (ASP.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Loading image to HTML
- Next Thread: Interpret HTTP (Content-Disposition) headers from an XMLHTTP object?
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array beta box browser captchaformproblem cart checkbox child close codes column css date debugger decimal dependent design disablefirebug dom download editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming prototype redirect runtime safari scale scriptlets scroll search security select shopping size software unicode w3c web window windowofwords wysiwyg \n






