jquery - != not working in javascript -


here prob,

i trying validate variable have value or no using if condition. not working expected. here code used,

var nextalbum = $('#contentplaceholder1_relatedphotos_hdnrelatedalbum').val();                if ((nextalbum != "") || (nextalbum != "undefined") || (nextalbum != undefined)) { window.location.href = nextalbum; } else { a.sliderun(-1, !0); } 

nextalbum shows value "undefined", if block executed rather else.

any appreciated.

you need use && because @ give time atleast 1 condition true.

if ((nextalbum != "") && (nextalbum != "undefined") && (nextalbum != undefined)) 

to explain - when use || @ time 1 of comparisons true, whole comparison true. since nextalbum = "undefined" first comparison true: nextalbum != "".

true || false = true false || false = false 

if use &&, reversed; if @ time 1 comparison false, false.

true && false = false true && true = true 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -