Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

jQuery $('#id').val() should not return null for a "disabled selected" HTML select option #20

@tkrotoff

Description

@tkrotoff
<select id="colorpicker">
  <option value="#7bd148">Green</option>
  <option value="#5484ed">Bold blue</option>
  <option value="#a4bdfc" selected disabled>Blue</option>
  <option value="#46d6db">Turquoise</option>
  <option value="#7ae7bf">Light green</option>
  <option value="#51b749">Bold green</option>
  <option value="#fbd75b">Yellow</option>
  <option value="#ffb878">Orange</option>
  <option value="#ff887c" selected disabled>Red</option>
  <option value="#dc2127">Bold red</option>
  <option value="#dbadff">Purple</option>
  <option value="#e1e1e1">Gray</option>
</select>

With jQuery

$('#colorpicker').val();

returns null

Without jQuery

// See How to get the selected value of dropdownlist using JavaScript? http://stackoverflow.com/questions/1085801/how-to-get-the-selected-value-of-dropdownlist-using-javascript
var e = document.getElementById('colorpicker');
e.options[e.selectedIndex].value;

returns "#ff887c"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions