Jump to content

Problem with looping setTimeout()


MacGoose

Recommended Posts

Hi!I have a problem when trying to loop with a setTimeout(). The problem has to do with sending a variable throught setTimeout. Like this:

function loopTimer( form ) {	...	if( form ) var timer = setTimeout( 'loopTimer( form )', ( ( form.hours.value * 3600000 ) + ( form.minutes.value * 60000 ) + ( form.seconds.value * 1000 ) ) );}

This way I can reuse the timer values collected in a form as you can see. I could put this in a global variable but I also use this function with no loop timer so when there is no form it will not loop. So by sending the form I tell it to loop, and so I need to be able to resend the form back through setTimeout()...TIA!, MacGoose

Link to comment
Share on other sites

If you want to reuse the form inputs, you can return the page after submission with value set, like so:<label>Text: <input type="text" name="sTextInput" id="sTextInput" value="LastValueSubmittedToServer" /></label>To test for the existence of the form, you can use document.getElementById('formid') and check it for null. If it's null, the form's not there.If you're trying to use the timer as some sort of ticker, you might want to use setInterval, and update the values on each 'tick'.

Link to comment
Share on other sites

If you want to reuse the form inputs, you can return the page after submission with value set, like so:<label>Text: <input type="text" name="sTextInput" id="sTextInput" value="LastValueSubmittedToServer" /></label>To test for the existence of the form, you can use document.getElementById('formid') and check it for null. If it's null, the form's not there.If you're trying to use the timer as some sort of ticker, you might want to use setInterval, and update the values on each 'tick'.
I don't want to reuse the form for the user to send it in again. I want to reuse the values in the form - in this case the user choosen timeout. Also I don't want to test if the form is in the webpage as I already know that. But I want to check if the function has been called from the form or not.Basically what I need to do is to send the form from one function back to the same function. As can easily be seen as I call the loopTimer( form ) function inside itself - the loopTimer( form ) function..., MacGoose
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...