<select id="selectBox">
<option value="all">all</option>
<option value="0">Number 0</option>
<option value="1">Number 1</option>
<option value="2">Number 2</option>
<option value="3">Number 3</option>
<option value="4">Number 4</option>
<option value="5">Number 5</option>
<option value="6">Number 6</option>
<option value="7">Number 7</option>
</select>
If the user select all option i need to get all the other option value like 0,1,2,3,4,5,6,7
My code is:
$("#selectBox").live('change', function () {
var val = this.value;
if (val == "all") {
$("#selectBox>option").map(function () {
alert($(this).val());
});
}
});
Any idea?
Try to use .map() along with .get() to accomplish your task,
var val=this.value;
var allValues = null;
if (val=="all") {
allValues = $("#selectBox > option:not(:first)").map(function() {
return this.value;
}).get(); //[0,1,2,3,4,5,6,7]
}
Full code would be,
$("#selectBox").live('change',function(){
var val=this.value;
var allValues = null;
if (val=="all") {
allValues = $("#selectBox > option:not(:first)").map(function() {
return this.value;
}).get(); //[0,1,2,3,4,5,6,7]
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With