28 users online (1 members and 27 guests)  


  Results 1 to 1 of 1

Related

  1. Javascript Function    Forum: Javascript Forum
    Replies: 0
  2. Javascript function call    Forum: Javascript Forum
    Replies: 1
  3. Replies: 5
  1. #1
    milind4's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2007
    Posts
    1

    Stopping a Javascript function with a button

    This is my page so far:

    Code:
    <html><head><title>Square Number Generator</title></head>
    <body>
    <form name="hi">
    <input type="text" name="the2">
    <br><br>
    <input type="button" value="Start" onclick="find_square();"><input type="button" value="Stop" onclick="find_square.stop();"><br><br>
    <textarea style="font-family : Times new roman;" name="blah" rows="50"></textarea>
    
    <script language="javascript">
    function find_square() {
    var the_go = 0;
    document.hi.blah.value = '1';
    var add = 3;
    var the_square = 1;
    var the = document.hi.the2.value;
    
    while (the_go < the) {
    the_square = the_square + add;
    document.hi.blah.value = document.hi.blah.value + '\n' + the_square;
    add = add + 2;
    the_go = the_go + 1;
    }
    
    }
    </script>
    I want to make it so that pressing the stop button will stop the function started by the start button. Thank you.
    Last edited by vinyl-junkie; 07-22-2007 at 07:37 PM. Reason: Added code tags