Skip to main content
Known Participant
October 23, 2024
Answered

JavaScript alert and if

I have to fields called 'Lmin' and 'Lmax' with values. 

Another Field 'Given L' is to be filled out, but must be equal to min og max - or in between. 

An alert is suppose to pop of if the enteres value does not meet the specification, and the value will be set to 0. 

I have made the validation for 'Given L' in javascript, but has a few things that keeps bugging me: 

- After activating the alert, the cursor is in the next field. I would like to return to the 'Given L'

 

At the end of the document I have a 'claer all fields'-button. 

It works ok, but the min-alert pops up when I activate it - and then clears the fields like it's supposed to.

 

JaveScript in validation of 'Given L':

var min = this.getField("Lmin").value;
var max = this.getField("Lmax").value;
var nValue = Number(this.getField("Given L").value);
if(nValue=0);
else if(event.value<min){
app.alert("WRONG min");
event.value = 0
};
if(event.value>max){
app.alert("WRONG max");
event.value = 0
};
event.value

This topic is closed to new replies. Start a new post to keep the conversation going.
PDF Automation Station
Community Expert
October 23, 2024

Change your script to the following:

var min = this.getField("Lmin").value;
var max = this.getField("Lmax").value;
var nValue = Number(event.value);
if(event.value<min){
if(app.alert("WRONG min")==1)
{
event.value = 0;
event.target.setFocus();
}
}
else if(event.value>max)
{
if(app.alert("WRONG max")==1)
{
event.value = 0;
event.target.setFocus();
}
};

14 replies

PDF Automation Station
Community Expert
Community Expert
October 23, 2024

Change your script to the following:

var min = this.getField("Lmin").value;
var max = this.getField("Lmax").value;
var nValue = Number(event.value);
if(event.value<min){
if(app.alert("WRONG min")==1)
{
event.value = 0;
event.target.setFocus();
}
}
else if(event.value>max)
{
if(app.alert("WRONG max")==1)
{
event.value = 0;
event.target.setFocus();
}
};
Translate
Nesa Nurani
Community Expert
Community Expert
October 23, 2024

You didn't use 'nValue'.

Translate
Known Participant
October 24, 2024

You might be right. I'm new to this JavaScript and trying to learn it by self-study, so I'm making some mistakes and useless stuff on the way - this could be one of them... 

Translate