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

If else Statement in PDF Form

New Here ,
Sep 06, 2018 Sep 06, 2018

Copy link to clipboard

Copied

Hi All,

I want to perform an action base on an initial value from a text field. There are 4 Checkboxes corresponding to numbers 1 to 4. So, if the text field starts with the number "1", the checkbox corresponding to 1 is checked while the others are not. Same goes with the number the "2", the checkbox corresponding to 2 is checked while the others are not.

My main problem is that I don't how to get the first value in the text field. E.g. 132XXXXXXX - It should get the value "1" and the checkbox for 1 should be checked.

var checkbox1 = this.getField("text field").value; // This is where the checkboxes should get the value of the first digit in the text field.

if (checkbox == 1) event.value = "YES"

else event.value = "NO"

I hope my question is clear.

Thank you and  Kind Regards.

TOPICS
PDF forms

Views

1.4K

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

correct answers 1 Correct answer

LEGEND , Sep 06, 2018 Sep 06, 2018

It would make sense to use a custom validate script for the tet field that contains the value that you want to check, something like:

// Custom validate script for text field

(function () {

    // Get a reference to each check box

    var f1 = getField("Checkbox1");

    var f2 = getField("Checkbox2");

    var f3 = getField("Checkbox3");

    var f4 = getField("Checkbox4");

    // Uncheck each check box

    f1.value = "Off";

    f2.value = "Off";

    f3.value = "Off";

    f4.value = "Off";

    // Don't continu

...

Votes

Translate

Translate
LEGEND ,
Sep 06, 2018 Sep 06, 2018

Copy link to clipboard

Copied

It would make sense to use a custom validate script for the tet field that contains the value that you want to check, something like:

// Custom validate script for text field

(function () {

    // Get a reference to each check box

    var f1 = getField("Checkbox1");

    var f2 = getField("Checkbox2");

    var f3 = getField("Checkbox3");

    var f4 = getField("Checkbox4");

    // Uncheck each check box

    f1.value = "Off";

    f2.value = "Off";

    f3.value = "Off";

    f4.value = "Off";

    // Don't continue if this field is blank

    if (!event.value) return;

    // Get the first character of this field

    var s1 = event.value.slice(0, 1);

    // Check the appropriate check box

    switch (s1) {

    case "1" :

        f1.checkThisBox(0, true);

        break;

    case "2" :

        f2.checkThisBox(0, true);

        break;

    case "3" :

        f3.checkThisBox(0, true);

        break;

    case "4" :

        f4.checkThisBox(0, true);

        break;

    default: // Do nothing if the first character is not 1-4

        break;

    }

})();

Change "Checkbox1" through "Checkbox4" to match the actual names of the checkbox fields.

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
New Here ,
Sep 06, 2018 Sep 06, 2018

Copy link to clipboard

Copied

LATEST

Yup! This works!

Thanks a lot!

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