Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resetting an input variable

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I've got an inactivity countdown javascript that I need to reset to the begining value if the user moves his/her mouse

<form name=jj>
<input type=text name=kk value=5 size=4 >
</form>


var id;

function countdown()
{
jj.kk.value--;
if ( jj.kk.value == 0 )
{
self.clearInterval(id);
gogogo();
}
}

function gogogo()
{
location.replace('}

id = self.setInterval('countdown();',1000);

</script>


I've tried to stick in

onMousemove=&quot;jj.kk.value = 5&quot;; at various places, but it's just not working - anyone got any ideas?

Thanks
 
try something like this:
notice that i have used the setAttribute() method to set the value for the control...
Hope this is ok.

Rhys.

<html>
<head>
<title>Untitled</title>
</head>

<body onLoad=&quot;fnStartInterval()&quot; onmousemove=&quot;setkk()&quot;>

<form name=jj>
<input type=text name=kk value=5 size=4 >
</form>

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--

function setkk()
{
document.jj.kk.setAttribute(&quot;value&quot;,&quot;5&quot;)
}

function fnStartInterval(){
window.setInterval(&quot;countdown()&quot;,1000);
}

function countdown()
{
if (document.jj.kk.value>0)
{
document.jj.kk.setAttribute(&quot;value&quot;, document.jj.kk.value -1)}
else
{gogogo()}

}

function gogogo()
{
window.location.replace(&quot;}

-->
</script>


</body>
</html>
 
Rhys,

Thanks for the response, but now the countdown isn't starting at all for some reason. I like your thinking on the problem though - any other suggestions?

Thanks again!

Nathan_11
 
Soryy mate...
i must have changed the code inbetweem checking and posting it. there where some ';'s in the wrong place i think...
give this a go:

<html>
<head>
<title>Untitled</title>
</head>

<body onLoad=&quot;fnStartInterval()&quot; onmousemove=&quot;setkk()&quot;>

<form name=jj>
<input type=text name=kk value=5 size=4 >
</form>

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--

function setkk()
{
document.jj.kk.setAttribute(&quot;value&quot;,&quot;5&quot;)
}

function fnStartInterval(){
window.setInterval(&quot;countdown()&quot;,1000)
}

function countdown()
{
if (document.jj.kk.value>0)
{
document.jj.kk.setAttribute(&quot;value&quot;, document.jj.kk.value -1)}
else
{gogogo()}

}

function gogogo()
{
window.location.replace(&quot;}

-->
</script>


</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top