Skip to main content
New Participant
January 6, 2022
Answered

Javascrip alert box

  • January 6, 2022
  • 2 replies
  • 835 views

Hello,

I am in need of help with getting an alert box to pop up when a text box has an "X".

The top script is to dispaly an X is a sum is over 20. I would like this to trigger the alert box. If the sum is below 20 then no action.  Currently the alert box pops up after each click regaurdless of the sum.

var TS = Number(this.getField("TS").value);
if (TS>=20) event.value = "X";
if ("X")app.alert("message", 3);

else event.value = "";

Thanks in advanced.

This topic has been closed for replies.
Correct answer BarlaeDC

Hi,

 

So you only want the alert to show when you are changing the value to "X" in which case you should be able to do this

var TS = Number(this.getField("TS").value);
if (TS>=20) {
event.value = "X";
app.alert("message", 3);
}else {
event.value = "";
}

2 replies

Brainiac
January 6, 2022

Just some more info. You may wonder why

if (TS>=20) event.value = "X";
if ("X")app.alert("message", 3);

did not work.

The answer is that you say if("X") but JavaScript has no idea what you mean by that. You know that you mean the last value you set. The test would need to be

if ( event.value == "X")  -- notice == not =.

But using { several ; different ; things } is a nicer solution.

BarlaeDC
BarlaeDCCorrect answer
Community Expert
January 6, 2022

Hi,

 

So you only want the alert to show when you are changing the value to "X" in which case you should be able to do this

var TS = Number(this.getField("TS").value);
if (TS>=20) {
event.value = "X";
app.alert("message", 3);
}else {
event.value = "";
}
New Participant
January 6, 2022

That worked. Thank you very much!