Skip to main content
Known Participant
November 8, 2021
Answered

Zero (0) not accepted as a value in required box

  • November 8, 2021
  • 2 replies
  • 515 views

Hello,

 

Apologies for the stupid quiestion! Im very new at this!

 

I have a peice of code that will let the user know that required text fields have not been filled in. the code is as follows:

 

if(this.getField("Text Field 1").value == "")

{

app.alert("must be filled in");

}

else if (this.getField("Text Field 2").value == "")

{

app.alert("must be filled in");

}

else

{

this.mailDoc({cTo: "Email Address", cSubject: this.getField("Text Field 1").valueAsString})

}
;

 

This works except it will not allow for an input of zero. This is fine on Text Field 1 as it should always be submitted as a 6 digit number, however on Text Field 2 it can be zero

 

I have tried setting as a numerical text field although this did not work

This topic has been closed for replies.
Correct answer try67

Use "===" instead of "==", and valueAsString instead of value.

2 replies

Brainiac
November 8, 2021

JavaScript is designed to make things easier for the programmer. In most languages things can be a string or a number but not both, but JavaScript magically converts. This is one of those cases where it is a complete pain.... !

try67
try67Correct answer
Community Expert
November 8, 2021

Use "===" instead of "==", and valueAsString instead of value.