This content originally appeared on CodeSource.io and was authored by Deven
Forms are an integral part of any website. Most websites often contain the Contact Us form. Forms collect the user information & send it to a server to store it in a database. In today’s post, we are going to learn how you can collect the user information via HTML forms & submit it to the sever.
<form name="subscriberForm" onsubmit="return submitForm()" method="post">
<label>Name: </label>
<input required type="text" name="firstName">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Form: Forms contain a collection of HTML elements to collect user info like input, text area, select, checkbox, radio, etc. If a required attribute is specified inside the HTML elements form will make sure that the user fills in the information & only after filling in the required info it will submit the form.
To submit the form, add a button whose type is submit & specify which function should be called once the form is submitted.
$('#subscriberForm').on('submit', function (e) {
e.preventDefault();
// process the data
});
You can also submit the form via jQuery, just listen to submit event on the form & process the data.
The post JavaScript Submit form example appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-10-19T05:56:30+00:00) JavaScript Submit form example. Retrieved from https://www.scien.cx/2021/10/19/javascript-submit-form-example/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.