Skip to main content | Turn off styling Default page style

Question & Answer index

Using jQuery,how do you get the value of a form input?

How do you get the value depends on what type of input it is.

See related:


Sample checkbox inputs India America Africa Srilanka show selection

Here is the HTML for the text input box and the "show selection" link:

For a checkbox input, because there may be multiple selections chosen, you need to

  1. Locate all checkboxes that are checked, using $('input:checkbox[name='CheckboxName']:checked')
  2. Loop through the checked checkboxes, using .each
  3. Append the values of each checked checkbox to each other, using .push

In this example, I pass the name of the checkbox group into the function and "alert" the result. You could easily change this to "return" the value or assign the value to a variable.