javascript - How can I ignore two null or unassigned values in jQuery? -


i have code compare 2 values verify identical:

$(document).on("blur", "[id$=boxsection5total]", function (e) {     var totalvalue = $(this).val();     var paymenttotalvalue = $('[id$=boxpaymentamount]').val();     if (totalvalue != paymenttotalvalue) {         console.log("the value in 'total' not equal previous value in 'payment total.'");         alert("the value in 'total' not equal previous value in 'payment total.' payment total " + paymenttotalvalue + " , total " + totalvalue);     }     else {         console.log("the value in 'total' equal previous value in 'payment total'");     } }); 

however, if both text elements left blank, fails - considered not equal (the "if (totalvalue != paymenttotalvalue)" condition true).

how can refactor code ignores cases both elements have been left blank?

something like:

$(document).on("blur", "[id$=boxsection5total]", function (e) {     var totalvalue = $(this).val();     var paymenttotalvalue = $('[id$=boxpaymentamount]').val();     if ((totalvalue == null) & (paymenttotalvalue == null)) {         return;     }     . . . }); 

?

both "boxsection5total" , "boxpaymentamount" text elements (textboxes).

if want check on null should try this.

if (totalvalue !== null && paymenttotalvalue !== null && totalvalue != paymenttotalvalue) 

if want check untruthy (also see here: javascript: how test if variable not null) can use this:

if (totalvalue && paymenttotalvalue && totalvalue != paymenttotalvalue) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -