jQuery Form Events

tutorial and example
tutorial and example

When a form control receives or loses focus or when form control value is modified by the user such as by typing text in a text input, select any option in a select box etc. then the form event fires.

To handle the form events here are some methods.

1) The change() Method

When the value of an element is changed then the jQuery change event occurs. When the change event occurs then the change () method attaches a function with it to run.

This event is only used with <textarea> boxes, <input> elements and <select> elements.

Syntax:

Example:

Try Now

2) The focus() Method

The focus() method of jQuery attaches an event handler function to an HTML form field.

When the form field gets focus then the function executes.

Syntax:

Example:

Try Now

3) The blur() Method

jQuery blur() method is used to remove focus from the element.

An event handler function is attached to an html element by the blur() method and that function is executed whenever the form field loses focus.

Syntax:

Example:

Try Now

4) The submit() Method

When a form is submitted then the submit event occurs and after occurring the submit event, submit() method triggers the submit event or attaches a function to run.

Syntax:

Example:

Try Now