6

I have a form which contains the method "POST" and action ="abc.php" and button type of <input type ="button"> I have a handler when i cick that button i want to send a request to abc.php but nothing is happening no action is being prformed.I dont want to change the <input type ="button"> to <input type="submit>.How do i submit the Form .Here is the code

<form name= "form1" id ="form1" action ="abc.php" method="post">
<input type ="button" id="mybutton" value ="Add"> 
......
//All form Elements.
</form>

$(document).ready(function() {
    //Load all elements
});
$("#mybutton").click(function(e){
    alert(true);
    //$("#frmpohdr").submit();
});

The Above Statement is giving error and i know we need to have button type of submit for this method.How do i submit the Form to the abc.php when i click the button .I have tried all $.ajax methods

3 Answers 3

8

Have you tried putting all the code inside ready?

Also, if the form's id is form 1 you should do this:

$("#form1").submit();

And to avoid the buttons default's behaviour you should also add this link inside click's function:

e.preventDefault();

I also recommend you having a look at jQuery Form Plugin: http://jquery.malsup.com/form/

I hope i helped :)

Sign up to request clarification or add additional context in comments.

1 Comment

"if the form's id is form1" - the # selector in jQuery is for ids, not names.
3
jq("#showDetail").click(function() {
            jq('#formName').submit();
});
<input type="button" id="showDetail" class="secondarybutton" value="Done" />

Comments

0

You will either submit the form through the HTML form (i.e. change the input type = submit) Or you could use the $.post/$.ajax

1 Comment

The question is about submitting the form using button and its not good to suggest to change the attribute to submit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.