Javascript

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

Posted by Weston Ganger on March 25, 2016

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:


Posted in Javascript and Tagged with forms javascript 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts