开发者

Unable to submit form using JQuery

So the scenario is on my page I have a form along with a countdown timer. If the countdown timer reaches 0:00 I have a statement which activates and is supposed to submit the form as it stands.

here is that statement:

if (Todays_Date >= Target_Date) {
        clearTimeout(timeoutID);
        $('#testForm').submit();
        alert("Timeup, Submitting exam....");
        return;
    }

what actually happens is, it fires, the timer stops (cleared timeout) and alert pops up. However th开发者_如何学Ce form does not submit and take the user to the action page.

I have copied all of the code into this jsFiddle to layout the basic principle.

the time of which countdown is targetted to is passed in the HTML at the bottom. you'll see the countdown() call.

I really am in a pickle and would appreciate someones help.

note: I know this is not a secure method etc.

many thanks


You have form element called submit:

<input name="submit" type="submit" value="Complete Test">

Change its name so something like:

<input name="btnSubmit" type="submit" value="Complete Test" />

And your code will work.

When the form contains element called submit, referring to formElement.submit will refer the element instead of the actual submit method - this is very common problem.


You use

$("#testForm").trigger('submit');

The way you went with is binding the submit event to a function, which means once submit occurs, something you specify in the function (that you don't have) will happen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜