Val Select = null if values ​​are disabled

I have a Select and all values ​​are disabled, how can I set a value for 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

+3


source to share


2 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>
      

Run codeHide result


+2


source


You must be specific about the value of the returned item.



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>
      

Run codeHide result


+3


source







All Articles