Handling Selection Changes

$("select").on("change",   function(e) {     select_change_code_here }); $("input[type=checkbox]").on("change",   function(e) {     checkbox_change_code_here }); $(" input[type=radio]").on("change",   function(e) {     radio_change_code_here });

Another important type of event to handle when working with forms is the selection change in check boxes, radio inputs, and select elements. All these elements have a change event handler that is triggered when the selection changes.

To handle selection changes on these items in jQuery, add the following event handler. Then put whatever change code you would like inside the handler function:

$("#formElement").on("change", ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.