Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Val of Select = null, if values is disabled

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

like image 974
Alex Avatar asked Mar 09 '23 06:03

Alex


1 Answers

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>
like image 62
Narayan Avatar answered Mar 12 '23 03:03

Narayan