views:

322

answers:

2

Hi,

i'm just using the JQuery validation plugin. i have the following spec: 'if the form isn't used in 10 seconds, give the user a warning, if he doesn't do anything, submit it anyway'

besides the timer etc. i have this code to submit the form:

timeoutId = setTimeout(function() {

$("#session_expired").val("true");
$("form:first").validate({
                    onsubmit: false
                });
$("form:first").submit();
}, 10000);

what it does: it sets a certain hidden field value and then it submits the form. I've added the validate function to make sure it doesn't validate in this case. Bu you might have guessed it: it doesn't work.

Anyone any clue?

Michel

A: 

I would remove each part of the function and then test it until I can find which part of the function is a failing. Also us firebug and console.log to trace what is happening within the function. e.g.

timeoutId = setTimeout(function() {
console.log('timeout')
}, 10000);
matpol
it does fire the function ($("form:first").submit();) after 10 seconds, but the validation doesn't 'stop' so i'm thinking maybe the $("form:first").validate({ onsubmit: false });isn't correct
Michel
+1  A: 

Try using the DOM method directly instead of jQuery submit method for the submit:

Replace

$("form:first").submit();

with:

document.forms[0].submit();

My guess is that:

$("form:first").validate({ onsubmit: false });

only applies to when the form is submited by a submit button push.

bang
i THINK that is a good guess (i'm not sure) but i KNOW this works.Thanks!
Michel