1

We are trying to link our form's submit button to work as a submit button and function the following Javascript.

Button:

<button type="submit" id="btn_submit" class="button button--red">Sign Up</button>

It works when we remove the id="btn_submit" to submit, but when we add the id="btn_submit" it implements the Javascript. How could we have the one button achieve both functions?

Javascript (beginning):

$("#btn_submit").on('click', function() {

Many, Many thanks!

3
  • 1
    $("#btn_submit").on('click', function(e) { e.preventDefault(); //do code $('form#myForm').submit(); try this way Commented Mar 30, 2016 at 2:02
  • @guradio Thanks soooooo much!! That's exactly what we needed!! Commented Mar 30, 2016 at 2:09
  • glad it works @Lanie909 mind if i put it as answer so you can accept it? Commented Mar 30, 2016 at 2:15

2 Answers 2

1
$("#btn_submit").on('click', function(e) { 
e.preventDefault(); //prevent the form from submitting
//do your code here
$('form#myForm').submit(); //submit your form here

One way to do this is dont submit your form on button click after doing all the other code you can submit your form manually

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

Comments

0
$("#btn_submit").on('click', function(e) {
    e.preventDefault();

    //do stuff

    $("#form").submit();
}

Where "#form" represents the id of your form. So if your form is "my_form", then change the above to read $("#my_form").submit();

Comments

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.