0
How to use inArray to check whether an array contains null value?
I am having 3 date field, while submitting I want to check whether any date field is empty using inArray , I tried but I am not getting the exact result.
3 ответов
+ 4
Can you please post your code here so we can see the code and can think what is wrong with it.
+ 1
ok I got it, there was a small error, :- if(jQuery.inArray(" ", arrdate) !== -1) instead of this ,
if(jQuery.inArray("", arrdate) !== -1) this should be given, earlier I had put a space in between, that was the mistake.
0
Sorry for the delay, here is the code:
------------------------------------------------------------------------------------
<td><input type="date" class="form-control" name="txtadddate[]" value="" /></td>
<td><input type="date" class="form-control" name="txtadddate[]" value="" /></td>
<td><input type="date" class="form-control" name="txtadddate[]" value="" /></td>
<script type="text/javascript">
var arrdate = $('input[name^="txtadddate"]').map(function() {
return $(this).val();
//alert($(this).val());
}).toArray();
if(jQuery.inArray(" ", arrdate) !== -1){
alert("no date");
}else{
alert("date");
}
</script>