Form


What is form ?

The form is a collection of various text fields, checkboxes, and many more things in which we can fill the data, which will get submitted later. There are various types of forms like some are for data collection, some are linked with a database that stores data in the database, some are for login purposes, etc. A form is a web page that contains a list of questions that you have to answer correctly. We can give conditions to each field in the form to check whether the data entered by the user is correct or not.

Forms in jQuery

jQuery helps to upgrade the HTML form to implement AJAX in it. The main methods in AJAX are ajaxForm and ajaxSubmit, which are used to collect the information and determine how to manage the submit process in form. Both of these methods give various options which are helpful in managing forms.

  • ajaxForm (options): This method prepares the form for submission by adding necessary event listeners. Using ajaxForm and the ready method, you can prepare the existing form for submission.
  • ajaxSubmit (options) : It submits the form to AJAX immediately. When a user clicks on the submit button ajaxSubmit acts. We can also handle the submission operation.

E.g.

			$('form').on('submit', function(e) {
  		  e.preventDefault(); // prevent native submit
    		$(this).ajaxSubmit({
            target: '#myResultsDiv'
    		})
     });