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.

8th Jun 2018, 6:30 AM
anshu
anshu - avatar
3 Réponses
+ 4
Can you please post your code here so we can see the code and can think what is wrong with it.
8th Jun 2018, 6:41 AM
Akash Pal
Akash Pal - avatar
+ 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.
12th Jun 2018, 4:23 AM
anshu
anshu - avatar
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>
11th Jun 2018, 9:09 AM
anshu
anshu - avatar