javascript - check if field value has changed with jquery -
i want conastantly check if value changes.. if user selects new value in input form want run js code..
<div class="select2-container country_to_state country_select" id="s2id_billing_country" style="width: 100%;"> <a href="javascript:void(0)" class="select2-choice" tabindex="-1"> <span class="select2-chosen" id="select2-chosen-1">schweiz</span> <abbr class="select2-search-choice-close" /> <span class="select2-arrow" role="presentation"> <b role="presentation"/> </span> </a> <label for="s2id_autogen1" class="select2-offscreen">land *</label> <input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-1" id="s2id_autogen1" /> </div> <select name="billing_country" id="billing_country" class="country_to_state country_select " tabindex="-1" title="land *" style="display: none;"> <option value="">land auswählen…</option> <option value="de" selected="selected">deutschland</option> <option value="ch">schweiz</option> <option value="at">Österreich</option> </select>
i've tried far (doesn't work)
$('#select2-chosen-1').change(function() { alert("change"); });
first off should never have 2 elements same id on page. use classes instead
<span class="select2-chosen">value 1</span> <span class="select2-chosen">value 2</span> $('input').on('change', '.select2-chosen', (function() { alert("change"); });
here have had implement delegated event listener input's dynamically generated select2
after page instantiation. listen it's change
event , alert
.
alternatively, give <input class="select2-focusser select2-offscreen"
, <select name="billing_country"..
class of someclass
, listen change
$('.someclass').change(function() { alert("change"); });
Comments
Post a Comment