jQuery Form Selectors are special selectors used to select form elements such as input fields, textboxes, checkboxes, radio buttons, and select dropdowns easily.
Form selectors allow you to directly target form-related elements without complex CSS selectors.
:input – Selects all input, textarea, select, button:text – Selects text inputs:password – Selects password fields:radio, :checkbox:checked – Selects checked inputs:disabled, :enabled:selected – Selects selected options
// Select all form elements
$(":input").css("border","2px solid blue");
// Highlight checked checkboxes
$(":checked").css("background","yellow");
// Disable all text inputs
$(":text").prop("disabled", true);
All input elements receive a blue border. Checked elements are highlighted, and text inputs become disabled.
// Show selected option value
$("select").change(function(){
alert($(this).val());
});
change and submit