jQuery

jQuery Value ( val() ) Examples

Ever wondered how to get the value of of a form element using jQuery? In this article,  I am going to show you different ways to use jQuery to get value of input elements.

How to use .val() method in jQuery to get Value

The most easiest way to get the value of an input element is to use the .val() method.

This can be used on form elements such as input, textarea and select.

Example 1: Get value of an input box with ID “state”

$('#state').val();

Example 2: Get value of an textarea with ID “comments”

$('#comments').val();

Example 3: Get value of a selected option of a select dropdown with ID “country”

$('#country option:selected').val();

Example 4: Another way to get value of a dropdown with ID “country”

$('#country').val();

Example 5: Get value of a checkbox with ID “subscribe”

$('#subscribe:checked').val();

Example 6: Get value of a radio button with ID “gender”

$('#gender:checked').val();
That’s it!

Do you know of any other implementations of using jQuery to get value by using .val(); method? Feel free to suggest by commenting below.

Share your thoughts, comment below now!

*

*