Er Sahaj Arora
Er Sahaj Arora

Reputation: 862

form.submit method is not work in jQuery

Form

 <form method="POST" name="form" id="form">
        <p>
            <input type="radio" name="ans1" value="A"> <br>
            <input type="radio" name="ans2" value="B"> <br>
            <input type="radio" name="ans3" value="C"> <br>
            <input type="radio" name="ans4" value="D"> <br>
            <input type="submit" name="send">  
        </p>
     </form>   

jQuery

$(document).ready(function()
{
    if(endTime <= time )
    {
        //alert('123'); //when fire condition then alert is working ;
        $("form").submit();
    }
});

Problem

When i click on send button then form submit by php
but if form does not submit i want to submit form automatic by jQuery , but form.submit is not working

When jQuery 'if condition' fire then page reload and hang page but form did not submit

Upvotes: 1

Views: 326

Answers (2)

Jaydeep Gondaliya
Jaydeep Gondaliya

Reputation: 331

Because when you call $( "#form" ).submit(); it triggers the external submit handler which prevents the default action, instead use

$( "#form" )[0].submit();  

or

$form.submit();//declare `$form as a local variable by using var $form = this;

When you call the dom element's submit method programatically, it won't trigger the submit handlers attached to the element

Upvotes: 3

mrid
mrid

Reputation: 5796

Try submitting the form using javascript if it works :

$(document).ready(function()
{
    if(endTime <= time )
    {
        //alert('123'); //when fire condition then alert is working ;
        document.getElementById("form").submit()
    }
});

And secondly, it's not a good practice to name a form form

Upvotes: 1

Related Questions