Build array from select inputs using class with JQuery -


i have multiple selects in jquery mobile. go through these , build array based on option value. code should check each select in class specific option value , place partial id name in array can populate textbox each select chosen "no". textbox show "1,3" if select sel1 , sel3 has no selected. fire off of button click.

<select id="sel1" data-role="slider" class="check">    <option value="0">no</option>    <option value="1">yes</option> </select> <select id="sel2" data-role="slider" class="check">    <option value="0">no</option>    <option value="1">yes</option> </select> <select id="sel3" data-role="slider" class="check">    <option value="0">no</option>    <option value="1">yes</option> </select>  $('#butreason').click(function() {     var values = $(".check").map(function() {         return this.value;     }).get(); }); 

my partial code poor appreciated. thank you.

a simple way check value of each select & return this.id. checkout fiddle

$('#butreason').click(function() {       var values = $(".check").map(function() {         if(this.value == 0) return this.id;     }).get();     $('#result').html(values); }); 

additionally, if id meant index, should split result on 'sel' , use that, pointed in comments question.

hope helps.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -