0

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.

teamo
  • 443
  • 1
  • 7
  • 16
  • possible duplicate of [jQuery Get Selected Option From Dropdown](http://stackoverflow.com/questions/10659097/jquery-get-selected-option-from-dropdown) – Anurag Jun 25 '15 at 21:02

3 Answers3

3

Change the query to something like

$('select[name=customer-country]').val();

since a select is not a input

depperm
  • 10,606
  • 4
  • 43
  • 67
0

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 >
aahhaa
  • 2,240
  • 3
  • 19
  • 30
0

try select

alert($("select[name=customer-country]").val())
marhs08
  • 57
  • 1
  • 1
  • 6