/    /  Javascript Form Methods

Javascript Form Methods

 

The submit method triggers when the form is submitted. It is usually provided to validate the form before sending it to the server or to abort the submission and process it in JavaScript.

The method form.submit() allows initiating form sending from JavaScript. We can use it to dynamically create and send your own forms to the server.

 

Syntax:

 

formobject.submit()

 

EXAMPLE:

 

<!DOCTYPE html>
<html>
<body>

<p>Enter some text in the fields below, then press the "Submit form" button to submit the form.</p>

<form id="myForm" action="/action_page.php">
 First name: <input type="text" name="fname"><br>
 Last name: <input type="text" name="lname"><br><br>
 <input type="button" onclick="myFunction()" value="Submit form">
</form>

<script>
function myFunction() {
 document.getElementById("myForm").submit();
}
</script>

</body>
</html>

 

OUTPUT:

 

Javascript Form Methods