I in my web page I have a number of hidden fields to identify if something has been printed, these are all start with 1 of 2 strings for the id so I have this:
var checker = true;
//Check Packing Slips
$("input[id^='OnePrintReference_']").each(function (i, e) {
if ($(this).val() === false) {
checker = false;
};
});
$("input[id^='TwoPrintReference_']").each(function (i, e) {
if ($(this).val() === false) {
checker = false;
};
});
//if check == false do nothing, else do something
However the problem is it is always returning true, even when I have used the debugger and alerts to establish that there are false values, i should I check to see if there is something to loop through as sometimes there won't be a TwoPrintReference_,and
whats the best way to do this
Participant
1620 Points
2443 Posts
I think I have a loop $(this) issue
Sep 12, 2018 02:26 PM|EnenDaveyBoy|LINK
Hi
I in my web page I have a number of hidden fields to identify if something has been printed, these are all start with 1 of 2 strings for the id so I have this:
However the problem is it is always returning true, even when I have used the debugger and alerts to establish that there are false values, i should I check to see if there is something to loop through as sometimes there won't be a TwoPrintReference_,and whats the best way to do this
All-Star
37221 Points
15032 Posts
Re: I think I have a loop $(this) issue
Sep 12, 2018 02:48 PM|mgebhard|LINK
A hidden field value type is a string not a Boolean. A string is never strictly equal to false.
The following link explains the === operator.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
How are you setting the hidden fields and what is the value?
All-Star
50854 Points
12100 Posts
Re: I think I have a loop $(this) issue
Sep 12, 2018 03:50 PM|bruce (sqlwork.com)|LINK
as .val() returns a string:
is always false. maybe you wanted
Contributor
2320 Points
911 Posts
Re: I think I have a loop $(this) issue
Sep 13, 2018 03:18 AM|Ackerly Xu|LINK
Hi EnenDaveyBoy,
As pointed out by mgebhard and bruce (sqlwork.com), your check will always return false.
If you want to check whether the value of your input is "".You could write you code as follows.
if ($(this).val() == false) { checker = false; };
Or directly
For more information falsy value, please refer to https://developer.mozilla.org/en-US/docs/Glossary/Falsy
Best regards,
Ackerly Xu
Please remember to "Mark as Answer" the responses that resolved your issue.
Participant
1620 Points
2443 Posts
Re: I think I have a loop $(this) issue
Sep 13, 2018 11:55 AM|EnenDaveyBoy|LINK
thanks for the replies.