2 Replies - 221 Views - Last Post: 20 August 2019 - 07:27 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 634
  • View blog
  • Posts: 4,218
  • Joined: 12-January 10

javascript function enters if even though it is 0

Posted 20 August 2019 - 05:11 AM

  var usedCtrl = parseInt(usedreasonsGVRowlength[x].cells[3].getElementsByTagName("input")[0].value.replace(',', ''));
                //alert(usedCtrl);
                if ((isNaN(usedCtrl)) || (usedCtrl == '') || (usedCtrl < 0)) {



not sure why the above gets entered into when the value is 0 --- it should skip this if but instead it goes in

Is This A Good Question/Topic? 0
  • +

Replies To: javascript function enters if even though it is 0

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,318
  • Joined: 12-December 12

Re: javascript function enters if even though it is 0

Posted 20 August 2019 - 06:54 AM

If you enter 0 == '' in the console it says true. This is to do with the falsity of values. Search 'Javascript falsy'.

If you try 0 === '' it says false.
Was This Post Helpful? 1
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 634
  • View blog
  • Posts: 4,218
  • Joined: 12-January 10

Re: javascript function enters if even though it is 0

Posted 20 August 2019 - 07:27 AM

that did the trick
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1