jquery - Get value of select on change with class name -


this question has answer here:

i using jquery add select in each row of table. selects assigned class name.

now, need value of select on change using dynamically assigned class name.

$select = $('<select class="medname"></select>');  for(var = 0;i < tmp.length-1; i++){                 $option = $('<option>'+tmp[i]+'</option>');                 $select.append($option); } 

here tmp contains data fetched backend.

finally,

    var $row = $('<tr></tr>');     var $data1 = $('<td></td>');     var $data2 = $('<td></td>');     var $data3 = $('<td></td>');     var $data4 = $('<td></td>');      //alert($select.html());      $data1.append($select);     $data2.append($type);     $data3.append($text);     $data4.append($label);      $row.append($data1);     $row.append($data2);     $row.append($data3);     $row.append($data4);      $row.insertafter('#cashmemobody'); 

this works fine.

now when do,

$('.medname').on('change', function (e) {         var val = $(this).find('option :selected').html();         alert(val); }); 

i not alert.

inspect element shows, classes assigned.

whats going wrong ?

here problem not dynamic binding, getting value of selected option. none of provided solutions seem work here. hence question.

it should be-

$(document).on('change','.medname',function(){   var val = $('option:selected',this).val()   alert(val); }); 

because .medname dynamically created


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -