Jack wrote:
[...]
Anyone know how you can get one button to stop a process started by
another???
What you are attempting is probably something like:
<input type="button" value="start" onclick="
keepGoing = true;
for (var i=0; i<100000 && keepGoing; i++) {
this.form.counter.value = i;
}
">
<input type="button" value="stop" onclick="
keepGoing = false;
">
When you click the "start" button, the counter starts. But the
script blocks further input until it is finished, so clicking the
"stop" button does nothing.
The trick is to start the script using setInterval - which will
run the script at a regular intervals - or setTimeout, which will
run the script after a specified delay. During the pauses, other
input will be accepted, such as a click on the "stop" button to
change keepGoing to false.
The effect you are looking for can be created using setTimeout as
follows:
<script type="text/javascript">
function startCount() {
if (y.value < 1000 && keepGoing) {
y.value -= -1;
setTimeout("startCount(y)",10);
}
}
</script>
<form action="">
<input type="text" name="counter" value="0">
<input type="button" value="start" onclick="
keepGoing = true; // global boolean
y = this.form.counter; // output cell is global too
y.value = 0; // reset value to zero
startCount(y);
">
<input type="button" value="stop" onclick="
keepGoing = false;
">
</form>
Though be warned, if the script that is run by setTimeout
consumes the entire delay, it will effectively block all input
anyway and you likely will not be able to enter further input.
--
Rob