How To Create A Form With No Action That Does Not Reload The Page Upon Submit

Posted by Weston Ganger

I wanted to create a form without any action associated so that I could perform a bunch of actions in javascript including AJAX

The normal way to do it is probably not to use a form element at all and just use inputs outside of a form.

A way I found thats pretty slick was to set the action to javascript void


<form action="javascript:void(0);"></form>

Then you can do whatever you want when the submit button is pressed without any reloads or anything getting in the way.

As a bonus this should act as a defence against malicious bots.


Related External Links:

Article Topic:Software Development - Javascript

Date:March 25, 2016

Recommended Posts