...

View Full Version : reset fails: onClick = doc.form.name.value=""



Beep
07-24-2002, 04:59 PM
New, but I've used this reset method successfully:

onClick = document.form.name.value=""

(from JSKit) but somehow it doesn't work in the code below -- values keep re-appearing in two text boxes. Is there something about the script itself as I've modified it that is the problem? The timer and counter work fine, the reset button does not. I've placed the script inside the <body> tags because I want to put the counter and reset buttons inside a page with other scripts once they're done. Thanks.

<body bgcolor="#FFFFFF">

<script language="JavaScript">
<!--
//on-screen timer
//JavaScriptKits at http://www.javascriptkit.com/
//modified by Bob Higgins
var c=0;
document.go.timer.value="";
function count()
{
document.go.timer.value=c;
c=c+1;
if (c>5){
document.go.timer.value=5;
document.go.txtMsg.value=("TIME IS UP!!!");
document.close();
}
setTimeout("count()",1000);
}

//-->
</script>

<form name="go">
<input type="text" name="timer" size="12">
<input type="button" value="Start" onClick="count()">
<input type="text" name="txtMsg" value="" size="26">
<input type="button"
name="resetButton"
value="Reset"
onClick = document.go.timer.value='';document.go.txtMsg.value=''
>
</form>

</body>

caldasgsm
07-24-2002, 05:13 PM
try instead of name attribute to use de ID attribute

adios
07-24-2002, 05:31 PM
Too many thing wrong to list them all...

<html>
<head>
</head>
<body bgcolor="#FFFFFF" onload="document.go.reset()">
<script language="JavaScript">
<!--
//on-screen timer
//JavaScriptKits at http://www.javascriptkit.com/
//modified by Bob Higgins
var c=0;
function count()
{
document.go.timer.value=c;
c=c+1;
if (c>5){
document.go.timer.value=5;
document.go.txtMsg.value="TIME IS UP!!!";
} else timerID = setTimeout("count()",1000);
}
//-->
</script>
<form name="go">
<input type="text" name="timer" size="12">
<input type="button" value="Start" onClick="count()">
<input type="text" name="txtMsg" value="" size="26">
<input type="button" name="resetButton" value="Reset"
onClick = "c=0;clearTimeout(timerID);timer.value='';txtMsg.value=''">
</form>
</body>
</html>

Beep
07-24-2002, 05:44 PM
Thanks caldasgsm and adios.

Adios, I have much to learn! and will study your successful changes. Key seems to be leaving out the 'else' statement after the 'if' and especially clearing the setTimeout -- a lesson I had not gotten to yet. Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum