
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to call a JavaScript function on submit form?
The onsubmit event occurs when you try to submit a form. You can put your form validation against this event type. The following example shows how to use onsubmit. Here we are calling a validate() function before submitting a form data to the webserver. If validate() function returns true, the form will be submitted, otherwise it will not submit the data.
<script> <!-- function validation() { all validation goes here ......... return either true or false } //--> </script>
The HTML code snippet.
<form method="POST" action="new.cgi" onsubmit="return validate()"> … <input type="submit" value="Submit" /> </form>
- Related Articles
- How to call a JavaScript function on click?
- How to call a JavaScript function on a click event?
- How to submit an HTML form using JavaScript?
- How to submit a form on Enter button using jQuery?
- Change value of input on form submit in JavaScript?
- How to call a function in JavaScript?
- How to call a Java function inside JavaScript Function?
- How do I call a JavaScript function on page load?
- How to delay a JavaScript function call using JavaScript?
- How to call a JavaScript function from C++?
- How to call a JavaScript function in HTML?
- How to call jQuery function with JavaScript function?
- How to submit a form in Selenium?
- How to call a function that returns another function in JavaScript?
- How to call a JavaScript Function from Chrome Console?

Advertisements