• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with If statement

Explorer ,
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

285

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!)

Votes

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
Community Expert ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

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

Votes

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

Votes

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
Community Expert ,
Aug 04, 2020 Aug 04, 2020

Copy link to clipboard

Copied

LATEST

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...

Votes

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