4

I have Select and all values is disabled, how can I set the value to this Select?

<select id="testselect">
   <option disabled>1</option>
   <option disabled>2</option>
   <option disabled selected="selected">3</option>
</select>

alert($("#testselect").val()); //result null

jsfiddle

Alex
  • 2,707
  • 4
  • 29
  • 42

2 Answers2

4

Try This ==>

alert($('#testselect option[disabled]:selected').val());
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<select id="testselect">
  <option disabled>1</option>
  <option disabled>2</option>
  <option disabled selected>3</option>
</select>
Narayan
  • 1,670
  • 1
  • 19
  • 37
3

You have to be specific about value of which element to return.

alert($("#testselect option:selected").val());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<select id="testselect">
  <option disabled>1</option>
  <option disabled>2</option>
  <option disabled selected>3</option>
</select>
Oen44
  • 3,156
  • 1
  • 22
  • 31