Reputation: 441
I'm trying to get the selected value
from a select
.
<select name="customer-country">
<option value="CA">Canada</option>
<option value="FR">France</option>
</select >
My problem is the code given in jQuery.com do not work.
alert($("input[name=customer-country]").val());
Any clue ?
Thanks.
Upvotes: 0
Views: 46
Reputation: 2275
select is not an input
$('select').on(
"change",
function() {
alert($(this).val());
}
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<select name="customer-country">
<option value="CA">Canada</option>
<option value="FR">France</option>
</select >
Upvotes: 0
Reputation: 10746
Change the query to something like
$('select[name=customer-country]').val();
since a select is not a input
Upvotes: 3