javascript - How should I catch a change in a bunch of dropdowns (in a table) and store it? -
i have table populated static data, 1 column contains dropdown built every row during foreach (item in array). while have same content, need treated separately. user change dropdown , choice needs stored.
i've seen jquery .change method, , according docs can go
$(document).ready(function(){ $( "input[type='select']" ).change(function() { console.log (input( $( ).val() ) }); }); to fire when there's change in of dropdowns. above doesn't log, nor error.
how monitor of dropdowns changes , store change?
or
would better off setting script per select monitor 1 assigned element? i'm not concerned performance or filesize, or ever. i'm using foreach populate rows , selected right option of dropdown
the problem you're using select, not input[type="select"]. that's incorrect one.
<table id="yourtableid"> <tr> <td> <select> <option value="blahxx">some text</option> .... .... </select> </td> </tr> </table> the input[type="xxx"] be:
- input
- password
- etc
what need jquery's on event, described below. difference b/w not having on event, , using change event, stated selects "cloned", meaning change event not set on these new cloned selects.
additionally, it's practice use below code, regardless if you're using on, or event (such change, click, etc.). says, "look @ element (usually id), , when event happens, apply elements in function". rather (without using way), "take these xxx elements , add event listener each 1 of them. why have xxxx event listeners when need one!
$(function() { <-- same using (document).ready $('#yourtableid').on('change','select', function(e) { // stuff here }); }); basically you're creating 1 event listener, rather xx. add listener table w/ xx id, , say, "watch selects within element xx id, , if change event happens, fire event".
the .on() method attaches event handlers selected set of elements in jquery object. of jquery 1.7, .on() method provides functionality required attaching event handlers. in converting older jquery event methods, see .bind(), .delegate(), , .live(). remove events bound .on(), see .off(). attach event runs once , removes itself, see .one()
Comments
Post a Comment