Try using the jQuery function to get the value of the element (wrapped in a jQuery object) .val()
rather than .value()
- this can cause some confusion, although I cannot be sure.
As a side note, your selector is incorrect for what you want. $('#x')
will return all elements having id
of x
- which should be only ever one element - then .each()
will .each()
over this set of elements (so that it will call the function once). You simply get an array containing one value, which will be the currently selected input value <select>
.
Instead, use $('#x > option')
, which will return all <option>
elements that are immediate children of the <select>
element with id
of x
.
source share