Expand my Community achievements bar.

SOLVED

Alert is not working

Avatar

Level 3

Hi there!

I have some Numeric Fields in which the user has to enter a number whithin a given range, I want that if the user enters a number that is outside the range, an alert is displayed and after that the focus is set on the same field. Also I need that the user has to be able to left the field empty.

So far I have the following code

form1.Subform4.NumericField11::exit - (JavaScript, client)

if (this.rawValue < 3 || this.rawValue > 7 && !(this.rawValue == "")){

          app.alert("Values is outside the allowable range")

          this.rawValue = "";

          xfa.host.setFocus("form1.Subform4.NumericField11");

}

If the user enters a number outside the range the alert is displayed and the Focus is set to the same field so he can enter s correct number. But if the user left the field empty the alert is displayed anyways.

Any ideas?

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 5

This works fine:

appAlert.jpg

if (this.rawValue < 4.5 || this.rawValue > 7 ){

          if (this.rawValue != null){

                    app.alert("Values is outside the allowable range");

                    this.rawValue = null;

                    xfa.host.setFocus("this");

          }

}

Or with the syntax of Kyle:

if (this.rawValue < 4.5 || this.rawValue > 7 ){

          if (!this.isNull){

                    app.alert("Values is outside the allowable range");

                    this.rawValue = null;

                    xfa.host.setFocus("this");

          }

}

Kind regards Mandy

View solution in original post

8 Replies

Avatar

Level 3

Thanks, I fixed the semi-colon but is still not working..

Avatar

Level 3

I also tried, but is not working

if (this.rawValue < 4.5 || this.rawValue > 7 ){

          if (this.rawValue != ""){

                    app.alert("Values is outside the allowable range");

                    this.rawValue = "";

                    xfa.host.setFocus("form1.Subform4.NumericField14");

          }

}

Avatar

Level 5

Can you keep the alert message out side of the If loop and check whether you are getting the message or not.

If you are getting then your if loop might be failing then check script syntax.

Vjay

Avatar

Level 3

I don´t understand what you mean..

Avatar

Level 8

To test for null (espcially for numeric fields), you need to replace the empty string test this.rawValue!="" with !this.isNull

Kyle

Avatar

Correct answer by
Level 5

This works fine:

appAlert.jpg

if (this.rawValue < 4.5 || this.rawValue > 7 ){

          if (this.rawValue != null){

                    app.alert("Values is outside the allowable range");

                    this.rawValue = null;

                    xfa.host.setFocus("this");

          }

}

Or with the syntax of Kyle:

if (this.rawValue < 4.5 || this.rawValue > 7 ){

          if (!this.isNull){

                    app.alert("Values is outside the allowable range");

                    this.rawValue = null;

                    xfa.host.setFocus("this");

          }

}

Kind regards Mandy