javascript - Get all selected="selected" values and put into array -
trying options selected="selected"
attribute on page.
there many of these instances on page can seem save first array.
how selected="selected"
shows up:
<select bind-event-change="disablehiddeninputs()" bind="appliestoresource6" id="link_list_links__link_type" name="link_list[links][][link_type]"> <option value="frontpage">store frontpage</option> <option selected="selected" value="collection">collection</option> <option value="product">product</option> <option value="catalog">all products</option> <option value="page">page</option> <option value="blog">blog</option> <option value="search">search page</option> <option value="http">web address</option> </select>
what have tried :
$('#link_list_links__link_type option:selected').map(function () { return $(this).val(); });
it returns first selected="selected"
option , not rest of iterations.
how return of options on page selected="selected"
? doing wrong?
the problem id have used, id of element must unique, when use id-selector return first element said id. means #link_list_links__link_type
selects 1 select element getting 1 value.
a unique identifier element.
there must not multiple elements in document have same id value.
one solution here use class group similar elements so
<select bind-event-change="disablehiddeninputs()" bind="appliestoresource6" name="link_list[links][][link_type]" class="link_list_links__link_type">
then
var array = $('.link_list_links__link_type option:selected').map(function () { return $(this).val(); }).get();
Comments
Post a Comment