Skip to content

Form action JavaScript void

  • by

Using JavaScript:Void(0) can eliminate the unwanted side-effect, because it will return the undefined primative value. Form action JavaScript void is used with hyperlinks.

<a href="javascript:void(0)">Link</a>

Form action JavaScript void

Simple example code used Form action=javascript:void to prevent the page from reloading when the button is clicked the first time.

<!DOCTYPE html>
<html>
   <body>
      <a href="javascript:void(0);" ondblclick="alert('Click it twice!')">Click me not once, but twice.</a>
   </body>
</html>

Output:

Form action JavaScript void

When doing this, you can use event.preventDefault() within an onclick event handler to prevent the page from refreshing.

Do comment if you have any doubts or suggestions on this Js form action topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading