admin管理员组文章数量:1022964
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) ...
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) ...
本文标签: javascriptCheck if variable is greater than something but not undefinedStack Overflow
版权声明:本文标题:javascript - Check if variable is greater than something but not undefined - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745487916a2152827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论