• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / jQuery Form Selectors

jQuery Form Selectors

There are a number of different <input> types in HTML and jQuery makes it simple to select the different types of input elements, such as all the text fields, all the radio buttons, all the submit buttons and so on. Full information and examples can be found on the selectors page of the jQuery document; this post gives some examples and a summary of the possible selectors.

Examples

The first example will match all the text type fields in a document:

$(':text')

To target a specific form use the following instead:

$('#myform :text')

Using a form id as in this second example also speeds up the selector because it does not have to scan the entire DOM to find all text inputs in the document.

To iterate through all the text fields and do something to them:

$('#myform :text').each(function() {
    // do something here
});

Substitute .each() for a different function depending on what is required.

Summary of selectors

$(‘:input’) matches all input and textarea fields.

$(‘:text’) matches all text type fields.

$(‘:password’) matches all password fields.

$(‘:radio’) matches all radio buttons.

$(‘:checkbox’) matches all checkboxes.

$(‘:submit’) matches all submit buttons.

$(‘:image’) matches all image type inputs.

$(‘:reset’) matches all reset buttons.

$(‘:button’) matches all input buttons with the type button.

$(‘:file’) matches all file upload fields.

Check Out These Related posts:

  1. Process Forking with PHP
  2. Clear a form with jQuery
  3. Style an HTML form input with CSS and jQuery
  4. Specify multiple selectors with jQuery

Filed Under: Javascript

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap