html - JQuery - option selected not allowing change -


i have jquery dynamically created form need able edit , change in option, code below picks selected value because second line of code sets default value defined selected, on changing drop-down, no matter select keeps original value - , presume because it's been selected second line, how break on changing option text (i have no values, text).

$('#msgbox4').html($('#msgbox4').html() + '<div class="table-row"><div class="table-col-l">type:</div><div class="table-col-r"><select id="type2" required="required"><option selected value="" disabled> -- select option -- </option><option>holiday</option><option>sick</option><option>working off site</option></select></div></div>') $("#type2 > option:contains('"+calevent.description+"')").attr("selected", "selected"); reason = $( "#type2 option:selected" ).text(); 

so variable reason returns selected result, not whatever change to.

this code shows selected option text in message box:

$("#msgbox4").on("change", "#type2", function() {     alert($(this).val()); }); 

here jsfiddle demo


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -