I am just using inArray() function in jquery but its not working. Actually I want check value in an array. I got lots of solutions on stackoverflow but nothing working that's why I created new post.
There is an hours format 1-24 and user can select their time slot like 1-3, 5-9, etc..
here is my code
jQuery('.select_hours').click(function(){
var favorite = new Array();
jQuery.each(jQuery("input[name='hour_count']:checked"), function(){
favorite.push(jQuery(this).val());
});
console.log(favorite);
var max_v = Math.max.apply(Math,favorite);
var min_v = Math.min.apply(Math,favorite);
// check the number sequence
for(var i = min_v; i <= max_v; i++){
if(jQuery.inArray(i,favorite) != -1){
alert('Hours in sequence!');
}else{
alert('Please select hours in sequence!');
}
}
});
Please help me in this..
Here is the HTML checkboxes and button:
<input type="checkbox" name="hour_count" id="hour_count_1" value="1"><input type="checkbox" name="hour_count" id="hour_count_2" value="2"><input type="checkbox" name="hour_count" id="hour_count_3" value="3"><button type="button" id="select_hours" class="select_hours">Select Hours</button>