jQuery :selected always returns the first option -
I'm trying to create a control function to check that the expected options from at least one selection list by the user has been chosen .
I have created this function which works, except that it always gives me the first option value for the element before the loop.
Example: For a selection list with 1: 'Foo' and 2: 'Bar', the warning gives me 'Foo', even though I have selected 'bar' in the selection list for the first time, But this is true for next selection values.
$ (document) .on ("click", "#submit", function () for {var n = 0; (var p = 0; p & lt; index; p ++) {var selectValue = $ ('# multiple_answer _' + P + '_ option: selected'). Val (); n ++; Alert ('option' + n + ':' + selectValue)}}) ;
If your'e using .val ()
: selected
var selectValue = $ ('# multiple_answer _' + + + p + '_ option') to retrieve the value of the selection Do not need to Val (); Also note , the array is zero indexed, so the id elements Should start with multiple_ answer_0_option
.
Comments
Post a Comment