Click to See Complete Forum and Search --> : 2 Buttons to call on and off javascript function


yphasukyued
05-20-2004, 07:51 AM
I have several buttons and one is call function from .js file.
It is a function to draw a rectangular by click and drag on the image,
but it's only draw it once unless user click this button again.
How can I make it to stay on until another button click?

<input type="image" src="darw.BMP" name="drawRect" onclick="init()">

theBody44
05-20-2004, 09:07 AM
Use recursion or a loop to make it keep running. Then when the other button is clicked, set a boolean value (ie. to true). In your reoccuring function, check to see if that boolean value is true, if it is, don't call the recursion, or break the loop.

yphasukyued
05-20-2004, 09:41 AM
Thanks for replied, but I'm new to programming. Do you have any sample?

theBody44
05-20-2004, 09:45 AM
You call "init()" when you click on the image darw.BMP. So with input 2 (the second button) call "setBool()". Then here is a sample script<script>
var ok2Go = false;
function setBool(){
ok2Go = true;
}

function init(){
//Do all the stuff your init() function does
//keep it exactly as it is...then add
if (!ok2Go){init();}
}This is called recursion. If you have not clicked on the second button (and set ok2Go to "true"), then the last line of init() will call init() again. It will repeat until you click on the second button. Hope this helps.

yphasukyued
05-20-2004, 01:50 PM
I got error "out of memory at line: 11"

theBody44
05-20-2004, 01:53 PM
What exactly does your init() function do? It sounds like it doesn't like you running it over and over again, in which case, you'll have to find another way to get around your original problem.