0
function checkmysize(){
var values = [];
var inputs = $('.size-col');
for(var i = 0; i < inputs.length; i++){
 values.push($(inputs[i]).val());
 alert(values);
}
}

my intention is count the same value in my array , i know i had to check the length and the value of each and push into a array , but how i count the same value in my array?

lets said if i got 3 s and 1 m , i want it to alert to like this s=3 , m=1, L=0. can any one give me a help ?

Demo

asked Nov 3, 2015 at 17:09
1

1 Answer 1

1

function checkmysize() {
 var values = [];
 var inputs = $('.size-col');
 for (var i = 0; i < inputs.length; i++) {
 values.push($(inputs[i]).val());
 }
 alert(values);
}
checkmysize();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
 <label>1.</label>
 <select class="size-col">
 <option value="s">S</option>
 <option value="m">M</option>
 <option selected value="l">L</option>
 </select>
</div>
<div>
 <label>2.</label>
 <select class="size-col">
 <option value="s">S</option>
 <option selected value="m">M</option>
 <option value="l">L</option>
 </select>
</div>
<div>
 <label>3.</label>
 <select class="size-col">
 <option value="s">S</option>
 <option selected value="m">M</option>
 <option value="l">L</option>
 </select>
</div>
<div>
 <label>4.</label>
 <select class="size-col">
 <option value="s">S</option>
 <option value="m">M</option>
 <option value="l">L</option>
 </select>
</div>

answered Nov 3, 2015 at 17:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.