How to iterated through selected s in ? [duplicate]












0
















This question already has an answer here:




  • Get value of multiselect box using jQuery or pure JS

    7 answers




There are many question already existing similar to this topic however I can't find any that address this specific problem.



If I have a <select> element where multiple selections are allowed, how can I iterate ONLY through ones that the user has SELECTED.



jQuery and/or Vanilla accepted.






select{
overflow:auto;
width: 150px;
}

<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>





http://jsfiddle.net/mtg73Lep/





Similar Posts that don't help:



Iterate through <select> options - For all options, not just selected ones



How to check if an item is selected from an HTML drop down list? - Doesn't work for multiple selections










share|improve this question















marked as duplicate by mplungjan html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 17:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    You must have searched inefficiently

    – mplungjan
    Jan 1 at 17:45











  • @mplungjan My bad. Thanks

    – JBis
    Jan 1 at 17:52













  • jsfiddle.net/mplungjan/k39nj8vw $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:52


















0
















This question already has an answer here:




  • Get value of multiselect box using jQuery or pure JS

    7 answers




There are many question already existing similar to this topic however I can't find any that address this specific problem.



If I have a <select> element where multiple selections are allowed, how can I iterate ONLY through ones that the user has SELECTED.



jQuery and/or Vanilla accepted.






select{
overflow:auto;
width: 150px;
}

<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>





http://jsfiddle.net/mtg73Lep/





Similar Posts that don't help:



Iterate through <select> options - For all options, not just selected ones



How to check if an item is selected from an HTML drop down list? - Doesn't work for multiple selections










share|improve this question















marked as duplicate by mplungjan html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 17:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    You must have searched inefficiently

    – mplungjan
    Jan 1 at 17:45











  • @mplungjan My bad. Thanks

    – JBis
    Jan 1 at 17:52













  • jsfiddle.net/mplungjan/k39nj8vw $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:52
















0












0








0









This question already has an answer here:




  • Get value of multiselect box using jQuery or pure JS

    7 answers




There are many question already existing similar to this topic however I can't find any that address this specific problem.



If I have a <select> element where multiple selections are allowed, how can I iterate ONLY through ones that the user has SELECTED.



jQuery and/or Vanilla accepted.






select{
overflow:auto;
width: 150px;
}

<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>





http://jsfiddle.net/mtg73Lep/





Similar Posts that don't help:



Iterate through <select> options - For all options, not just selected ones



How to check if an item is selected from an HTML drop down list? - Doesn't work for multiple selections










share|improve this question

















This question already has an answer here:




  • Get value of multiselect box using jQuery or pure JS

    7 answers




There are many question already existing similar to this topic however I can't find any that address this specific problem.



If I have a <select> element where multiple selections are allowed, how can I iterate ONLY through ones that the user has SELECTED.



jQuery and/or Vanilla accepted.






select{
overflow:auto;
width: 150px;
}

<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>





http://jsfiddle.net/mtg73Lep/





Similar Posts that don't help:



Iterate through <select> options - For all options, not just selected ones



How to check if an item is selected from an HTML drop down list? - Doesn't work for multiple selections





This question already has an answer here:




  • Get value of multiselect box using jQuery or pure JS

    7 answers







select{
overflow:auto;
width: 150px;
}

<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>





select{
overflow:auto;
width: 150px;
}

<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>






javascript jquery html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 17:53







JBis

















asked Jan 1 at 17:38









JBisJBis

302414




302414




marked as duplicate by mplungjan html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 17:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by mplungjan html
Users with the  html badge can single-handedly close html questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 17:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2





    You must have searched inefficiently

    – mplungjan
    Jan 1 at 17:45











  • @mplungjan My bad. Thanks

    – JBis
    Jan 1 at 17:52













  • jsfiddle.net/mplungjan/k39nj8vw $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:52
















  • 2





    You must have searched inefficiently

    – mplungjan
    Jan 1 at 17:45











  • @mplungjan My bad. Thanks

    – JBis
    Jan 1 at 17:52













  • jsfiddle.net/mplungjan/k39nj8vw $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:52










2




2





You must have searched inefficiently

– mplungjan
Jan 1 at 17:45





You must have searched inefficiently

– mplungjan
Jan 1 at 17:45













@mplungjan My bad. Thanks

– JBis
Jan 1 at 17:52







@mplungjan My bad. Thanks

– JBis
Jan 1 at 17:52















jsfiddle.net/mplungjan/k39nj8vw $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

– mplungjan
Jan 1 at 17:52







jsfiddle.net/mplungjan/k39nj8vw $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

– mplungjan
Jan 1 at 17:52














1 Answer
1






active

oldest

votes


















1














Try this:






$('select').change(function(){
$('option:selected').each(function(){
alert( $(this).text() );
});
});

select{
overflow:auto;
width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>







Another excellent (better? definitely cooler!) suggestion, by resident j-Maven mplungjan:



$("#the_select").on("change",function() { 
console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() )
});





share|improve this answer





















  • 1





    $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:54











  • Excellent code suggestion - many thanks. Love the Ask-Me-A-Question service on your personal site - best regards for 2019!

    – gibberish
    Jan 2 at 17:10











  • Yw- it’s a continuation from irt.org - have answered a million+ questions since ‘97

    – mplungjan
    Jan 2 at 17:12











  • And thanks for the kind words

    – mplungjan
    Jan 2 at 19:01


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try this:






$('select').change(function(){
$('option:selected').each(function(){
alert( $(this).text() );
});
});

select{
overflow:auto;
width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>







Another excellent (better? definitely cooler!) suggestion, by resident j-Maven mplungjan:



$("#the_select").on("change",function() { 
console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() )
});





share|improve this answer





















  • 1





    $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:54











  • Excellent code suggestion - many thanks. Love the Ask-Me-A-Question service on your personal site - best regards for 2019!

    – gibberish
    Jan 2 at 17:10











  • Yw- it’s a continuation from irt.org - have answered a million+ questions since ‘97

    – mplungjan
    Jan 2 at 17:12











  • And thanks for the kind words

    – mplungjan
    Jan 2 at 19:01
















1














Try this:






$('select').change(function(){
$('option:selected').each(function(){
alert( $(this).text() );
});
});

select{
overflow:auto;
width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>







Another excellent (better? definitely cooler!) suggestion, by resident j-Maven mplungjan:



$("#the_select").on("change",function() { 
console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() )
});





share|improve this answer





















  • 1





    $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:54











  • Excellent code suggestion - many thanks. Love the Ask-Me-A-Question service on your personal site - best regards for 2019!

    – gibberish
    Jan 2 at 17:10











  • Yw- it’s a continuation from irt.org - have answered a million+ questions since ‘97

    – mplungjan
    Jan 2 at 17:12











  • And thanks for the kind words

    – mplungjan
    Jan 2 at 19:01














1












1








1







Try this:






$('select').change(function(){
$('option:selected').each(function(){
alert( $(this).text() );
});
});

select{
overflow:auto;
width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>







Another excellent (better? definitely cooler!) suggestion, by resident j-Maven mplungjan:



$("#the_select").on("change",function() { 
console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() )
});





share|improve this answer















Try this:






$('select').change(function(){
$('option:selected').each(function(){
alert( $(this).text() );
});
});

select{
overflow:auto;
width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>







Another excellent (better? definitely cooler!) suggestion, by resident j-Maven mplungjan:



$("#the_select").on("change",function() { 
console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() )
});





$('select').change(function(){
$('option:selected').each(function(){
alert( $(this).text() );
});
});

select{
overflow:auto;
width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>





$('select').change(function(){
$('option:selected').each(function(){
alert( $(this).text() );
});
});

select{
overflow:auto;
width: 150px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<select id="the_select" size="5" multiple>
<option>Bob</option>
<option>John</option>
<option>Sam</option>
<option>Jason</option>
<option>Sarah</option>
</select>






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 17:04

























answered Jan 1 at 17:47









gibberishgibberish

21.4k105782




21.4k105782








  • 1





    $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:54











  • Excellent code suggestion - many thanks. Love the Ask-Me-A-Question service on your personal site - best regards for 2019!

    – gibberish
    Jan 2 at 17:10











  • Yw- it’s a continuation from irt.org - have answered a million+ questions since ‘97

    – mplungjan
    Jan 2 at 17:12











  • And thanks for the kind words

    – mplungjan
    Jan 2 at 19:01














  • 1





    $("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

    – mplungjan
    Jan 1 at 17:54











  • Excellent code suggestion - many thanks. Love the Ask-Me-A-Question service on your personal site - best regards for 2019!

    – gibberish
    Jan 2 at 17:10











  • Yw- it’s a continuation from irt.org - have answered a million+ questions since ‘97

    – mplungjan
    Jan 2 at 17:12











  • And thanks for the kind words

    – mplungjan
    Jan 2 at 19:01








1




1





$("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

– mplungjan
Jan 1 at 17:54





$("#the_select").on("change",function() { console.log( $("option:selected",this).map(function() { return $(this).val() } ).get() ) });

– mplungjan
Jan 1 at 17:54













Excellent code suggestion - many thanks. Love the Ask-Me-A-Question service on your personal site - best regards for 2019!

– gibberish
Jan 2 at 17:10





Excellent code suggestion - many thanks. Love the Ask-Me-A-Question service on your personal site - best regards for 2019!

– gibberish
Jan 2 at 17:10













Yw- it’s a continuation from irt.org - have answered a million+ questions since ‘97

– mplungjan
Jan 2 at 17:12





Yw- it’s a continuation from irt.org - have answered a million+ questions since ‘97

– mplungjan
Jan 2 at 17:12













And thanks for the kind words

– mplungjan
Jan 2 at 19:01





And thanks for the kind words

– mplungjan
Jan 2 at 19:01





Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas