dimanche 26 février 2017

Checkbox causes infinite loop

So I'm making a program using html en Javascript where the user can click a button and the program will perform a calculation and a checkbox that when checked will perform that same calculation in a loop.

  <body>
  <button onclick="javascript:calc();"> Calculate</button>
  <form action="">
   <input id="checkbox" type='checkbox' name='auto' value='Auto' /> 
  </form>

   <script>
    var checkbox = document.getElementById('checkbox');
   function calc() {
     do{
    //Calculate stuff
     }while(checkbox.checked);
    }
   </script>

   </body>

Problem is that when I check the checkbox the webpage just freezes because it is stuck in an infinite loop so I can't uncheck the checkbox to stop it.

Is there any way to stop it from going into an infinite loop?




Aucun commentaire:

Enregistrer un commentaire