0

input name="currency1" class="currency"

input name="currency2" class="currency"

input name="weight1" class="weight"

input name="weight2" class="weight"


function init(){

    var ZERO = 0;
    var currency= $(".currency").val();

    if(currency== '' || currency.length == 0){
        $(".currency").val(ZERO.toFixed(2));
    }
    else if(currency!= '' || currency.length != 0){
        $(".currency").val();
    }

}

when currency1 is fill it should not change but when it is empty it should print zero

Flowerking
  • 2,551
  • 1
  • 20
  • 30
Manzoor
  • 13
  • 5

1 Answers1

0

Just use '===' for comparing instead of '==' (Why?)

Try this,

(function(){

    var ZERO = 0;
    var currency= $(".currency").val();

    if(currency=== '' || currency.length === 0){
        $(".currency").val(ZERO.toFixed(2));
    }
    else if(currency!== '' || currency.length !== 0){
        $(".currency").val();
    }

}());

Demo Here...

Community
  • 1
  • 1
Flowerking
  • 2,551
  • 1
  • 20
  • 30