Reputation: 158
the html is
<select class='pay-type' style='width:100%'>
<option>Credit Card</option>
<option>Cash</option>
<option>Credit Note</option>
option>Gift Voucher</option>
<option>Cheque</option>
</select>
i reproduce this select by inserting the same html onto new div's. i have a module written which triggers when selection changes in the dropdown. How do i get the selected value of the exact dropdown in the onclick function? the following code doesnt seem to work.
$('.pay-type').change(function(){
console.log($(this).filter('option :selected'));
});
Upvotes: 1
Views: 68
Reputation: 1610
You are missing a .text()
$('.pay-type').change(function(){
console.log($(this).filter('option :selected').text()); // to show the text
console.log($(this).val()); // to show the value
});
Note: There are a few things off in your code.
text
method only.option
as Select a payment method, the user can also select the Credit card option to show in the selected div. Now to do the same thing, the user will have to select something else first and then go back and select that option to see itUpvotes: 2