javascript - Select drop-down value using Jquery -


please find below code, have drop down selected value dynamically not getting it.

<div class='box' id='dispositions'>     <div class='header'>dispositions</div>     <form>         <select name='rebuttal'>             <option value=''>---rebuttals count---</option>                 <option value='0'>0</option>                 <option value='2-3'>2-3</option>                 <option value='3 or greater'>3 or greater</option>         </select>     </form>     </div> 

to achieve using below code not giving expected result.

no alert getting below:-

$(document).ready(function(){     $('#cc-panel-disposition form [name=rebuttal]').change(function() {     alert($("#cc-panel-disposition form [name=rebuttal] option:selected").text());   });   }); 

in below code getting 'rebval' instead of selected value. please me here.

var rebval = $('#cc-panel-disposition [name=rebuttal]').find('option:selected').val(); //var test = $('#cc-panel-disposition form [name=rebuttal] option:selected').val();                 formvalues.rebval = rebval;//rebval; 

please let me know if need provide more information.

you have few mistake in selector, first of not have id cc-panel-disposition rather have dispositions secondly using instead of using same selector again in event handler.

live demo

$('#dispositions form [name=rebuttal]').change(function() {        alert($(this).find(':selected').text()); });   

you can use name selector bind event, if not expect other control same name

$('[name=rebuttal]').change(function() { ....  

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -