javascript-tutorialsmade

Two submit buttons in a HTML Form using JavaScript!

I’m going to show you how to use two submit buttons in a Form using JavaScript. It’s not so hard as you think.

First start with a Normal HTML form with two buttons:

If you see the above form, I had put two buttons one is “type=submit” button and other one is normal “type=button”. But, in the normal button there is a function added onClick ie., (onclick=”submitForm()”)

Now, lets see the JavaScript:

So, when the normal button is clicked, submitForm() function will be called and inside the function first we are going to display an alert and then submit the form.

Why to display an alert?
Just to show you the difference which button is clicked and also you can do other functionality before submitting the form.

Here is the entire code, so you can play with that:

Also, see the demo here 🙂

demo

 

 

Related Posts

Leave a Reply