Search within TutorialsPark

Jquery Form Elements


Learn to use jQuery to get and set the value of form Elements


jQuery Manipulating Element: Working with Form Elements

The jQuery can be used to get and set the value of form elements, by making use of val method.


Table : The Val Method

Method Description
val() To return the value of the first element in the jQuery.
val(val) To set the value of all of the elements in the jQuery object.
val(function) To set the values for the elements in the jQuery object using a function.

jQuery Manipulation : Get the Value of input Element using val() Method

The jQuery val() method is used to get the value from the first element in the jQuery object.

Example: Get the Value of input Element using val() Method

Give it a TRY! » Note: It returns a jQuery Object, which can be used for chaining purposes


Setting Form Element Values using val(value) method

The jQuery method of val(value) is used to set the value of all of the elements in the jQuery object, by simply passing the value as an argument for the method.

Example: Setting Form Element Values using val(map) method

Give it a TRY! » Note:It is typically used to set the values of form fields.


Setting Form Element Values using a Function

The jQuery method of val(function) can used with a function as an argument to set values.

Example: Setting Form Element Values using a Function

Give it a TRY! » Note:The arguments of to function are the index of the element and the currentValue.