From: MG on
I am a newbie.

On this page:
http://www.blighty.co.za/resetform/
I am testing a script to reset a form after it has been submitted.

I have this line:
setTimeout('mf.reset()',10000);
There should be a 10 second delay before the form resets. But the form
resets almost immediately.

I have stared at the code for a long time and just cannot figure out why
there is no 10 second delay.

Hope someone can help.

Thanks
MG


From: Gregor Kofler on
Am 2010-06-20 20:13, MG meinte:
> I am a newbie.
>
> On this page:
> http://www.blighty.co.za/resetform/
> I am testing a script to reset a form after it has been submitted.
>
> I have this line:
> setTimeout('mf.reset()',10000);

mf.reset() is executed immediately and the result becomes the argument
for the setTimeout method.

window.setTimeout(mf.reset, 10000);

is what you want.


Gregor


--
http://www.gregorkofler.com
From: Luuk on
Op 20-6-2010 20:13, MG schreef:
> I am a newbie.
>
> On this page:
> http://www.blighty.co.za/resetform/
> I am testing a script to reset a form after it has been submitted.
>
> I have this line:
> setTimeout('mf.reset()',10000);
> There should be a 10 second delay before the form resets. But the form
> resets almost immediately.
>
> I have stared at the code for a long time and just cannot figure out why
> there is no 10 second delay.
>
> Hope someone can help.
>
> Thanks
> MG
>
>

change 'return true' to 'return false'
so your form does not get submitted,
which clears the form

there is an additional bug in the function,
but my knowledge of javascript will not allow to solve it now ;)

--
Luuk
From: Garrett Smith on
On 2010-06-20 11:13 AM, MG wrote:
> I am a newbie.
>
> On this page:
> http://www.blighty.co.za/resetform/
> I am testing a script to reset a form after it has been submitted.
>

That sounds like an unpleasant user experience.

> I have this line:
> setTimeout('mf.reset()',10000);

function clearForm(mf){
setTimeout('mf.reset()',10000);
return true;
}

What happens when you return true from an event handler?
https://dev.mozilla.jp/localmdc/developer.mozilla.org/en/xul_tutorial/more_event_handlers.html#Prevent_Default_Action

What scope does the host method `setTimeout` use?
http://msdn.microsoft.com/en-us/library/ms536753%28VS.85%29.aspx

MDC and MSDN, as well as many other resources, are linked from the FAQ.

Please see: http://jibbering.com/faq/

Garrett
From: Garrett Smith on
On 2010-06-20 11:40 AM, Gregor Kofler wrote:
> Am 2010-06-20 20:13, MG meinte:
>> I am a newbie.
>>
>> On this page:
>> http://www.blighty.co.za/resetform/
>> I am testing a script to reset a form after it has been submitted.
>>
>> I have this line:
>> setTimeout('mf.reset()',10000);
>
> mf.reset() is executed immediately and the result becomes the argument
> for the setTimeout method.
>

No, that is not what happens.

When setTimeout is supplied a string argument, as is the case with
'mf.reset()', the string is evaluated after pausing for the delay given
as the second parameter, in this case 10000 ms.

setTimeout("alert(1)", 10000);

In the OP's example, the function is not called for a different reason.
The OP is still trying to figure that out, so I'm not going to give that
reason away.

> window.setTimeout(mf.reset, 10000);
>
> is what you want.

Passing the value of `mf.reset` to setTimeout will cause the function to
execute in 10000 ms with a null base object. That cannot be expected to
work reliably.

It will submit the form in most versions of IE, but will result in an
error in other implementations. MSIE is a notable exception, as its host
objects tend to retain a reference to their base object.

http://msdn.microsoft.com/en-us/library/ms536753%28VS.85%29.aspx

Garrett