Help with If statement

New Here ,
Jul 22, 2020 Jul 22, 2020

Copy link to clipboard

Copied

Hi All,

 

I have dropdown box called BERTH that has the following options to select from

"SCPT" "WBCT" "GOR1" and a few other options

 

I have second field called Berth_Depth that should return a set value based one of the above selections, for example, when SCPT is selected "Berth_Depth" should return a value of 10.0, WBCT should return a value of 10.8 and GOR1 should return a value of 13.3 and so on. There about 20 different options all up.

 

I have been using a variation of the the following code elsewhere in the PDF form for differnt fields, and it works. But when I transposed it to my "BERTH" field and changed the values etc it will not work. I have no idea why?? Please Help.......

 

if(event.value=="SCPT"){

  this.getField("Berth_Depth").value="10.0";

}

 

Thank you

LC

TOPICS
Edit and convert PDFs, PDF forms

Views

50

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

/*script */
var bd = this.getField("Berth_Depth");
if (event.value !="" && event.value !=' '){
    //Nothing was entered
    bd.value = 0
}else if (event.value=="SCPT"){
    //SCPT
    bd.value = 10.0
}else if (event.value=="WBCT"){
    //SCPT
    bd.value = 10.8
}else if (event.value=="GOR1"){
    //SCPT
    bd.value = 13.0
}else{
    //Different value was added ??
    app.alert("Value Error",0);
}

 

 

 

I usually add a value with a single space to the dropdowns to which it defaults so people explicitly have to make a choice.

 

hope it helps

 

P.S. I see I messed up the comments (oops!)

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

The code is incorrect. You used the wrong operators for the comparisons.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

Yep, woops x2!

 

attempted a quick fix

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

I believe this line is still incorrect:

if (event.value !="" && event.value !=' '){

You probably meant it to be:

if (event.value =="" || event.value ==' '){

Otherwise it contradicts the other conditions in your code...

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines