var ship = $("input[name=shippingamt]").length;
var counting1 = $(".submit-btn-1 li.checked:not(.title)").length;
if ((counting1 == 6)&&(ship >= 1)&&($('input[name=ideclare1]').is(":checked"))){
The above snippet is what I have so far, pretty much I have a 3 essential fields, a variable called Ship, an checklist called counting1 and a checkbox check.
But if Ship and Checklist are fine and the checkbox called ideclare1 is checked and unchecked then the value ship goes to undefined and is still class as valid as the length is >= 1.
Can any suggest how to check if a field is defined and has a length greater than 1?
Regards,
Donald
var ship = $("input[name=shippingamt]").length;
var counting1 = $(".submit-btn-1 li.checked:not(.title)").length;
if ((counting1 == 6)&&(ship >= 1)&&($('input[name=ideclare1]').is(":checked"))){
The above snippet is what I have so far, pretty much I have a 3 essential fields, a variable called Ship, an checklist called counting1 and a checkbox check.
But if Ship and Checklist are fine and the checkbox called ideclare1 is checked and unchecked then the value ship goes to undefined and is still class as valid as the length is >= 1.
Can any suggest how to check if a field is defined and has a length greater than 1?
Regards,
Donald
Share Improve this question edited Jul 11, 2012 at 15:41 ngplayground asked Jul 11, 2012 at 15:23 ngplaygroundngplayground 21.7k37 gold badges98 silver badges175 bronze badges1 Answer
Reset to default 2Check the .length
of the jQuery object.
var ideclare = $('input[name=ideclare1]');
if ((counting1 == 6)&&(ship >= 1)&&(ideclare.length > 0 && ideclare.is(":checked"))){
edit well if you're just checking a regular variable, just pare it to undefined
:
if (counting1 == 6 && (ship !== undefined && ship >= 1) ...