jquery - Having trouble returning the correct values for one element in this function -


i'm having trouble getting 'var haslining' function work properly. should return "0" or "1", depending upon if there lining. can't figure out why, causing function return wrong answer (i'm not sure what's happening, looks it's giving value next equation).

i've posted fiddle demonstrate problem: jsfiddle.net/chayacooper/9nkjt/1

var isthickerfabric = function() {   var item = $("[name=item]").val();   return item == "blazer" || item == "jacket" || item == "outerwear"; } var haslining = function() {   var lining = $("[name=lining]").val();   return lining != "0"; }  $("[name=item],[name=fabric_type],[name=lining]").change(function(){     if ( $("[name=fabric_type]").val() === "satin" ) {     var fabricthicknesselement = $('[name=fabric_thickness]');      if ( isthickerfabric() && !haslining || !isthickerfabric() && haslining ) {       fabricthicknesselement.val('2');     } else if ( isthickerfabric() && haslining() ) {       fabricthicknesselement.val('3');     } else {       fabricthicknesselement.val('1');     }   }     }); 

var haslining function check whether [name=lining] has value "0" or not, return true when [name=lining] field empty or value other 0, return false when value 0,

that's why value of fabricthicknesselement 3 because true form var haslining

if want result on bases on whether lining empty or not. change var haslining

return lining != ""

and change condition to

if ((isthickerfabric() && !haslining()) || (!isthickerfabric() && haslining()))


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -