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

Fill field depending on checkbox selection

Engaged ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

Hello

I have 3 checkboxes for class timings and the person can only choose 1 of the 3.

Depending on the checkbox ticked, a text field at the bottom (called (txtOfficeClass) is filled with text.

I have searched the forum and placed the following scripts (mouseup) in each check box. It works, but i want to know if i have done in correctly (in case something wrong happens in the future)

 

CheckBox 1

(function ()

  { // Get a reference to the text field var f = getField("txtOfficeClass"); if (event.target.value === "Off") {      

    f.value = ""; // Blank the statement field

    f.readonly = false; // Allow user to enter text } else {

    f.value = "CLASS 1 (16:30 TO 18:00)"; // Set field text

    f.readonly = true; // Don't allow user to enter text }

})();

 

Screenshot 2023-01-19 at 12.13.32.png

TOPICS
Acrobat SDK and JavaScript

Views

486

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

Engaged , Feb 12, 2023 Feb 12, 2023

ok

Votes

Translate

Translate
Community Expert ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

The code contains a couple of unnecessary items that affect efficiency, rather than function. And it's poorly formatted, which I'm sure is an artifact of pasting it directly into the forum message. Still, it'd be helpful if you would clean up your code formaating and use the "code box", so we can easily see what's actually going on. 

 

1. There is no reason to put this code in the function format.

2. There is no reason to use the identity operator for testing the checkbox value.

 

Otherwise, it looks great.  

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Engaged ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

 I just changed the check box to a radio button as it was selecting more than one option on mobile.

 

The code box is below after following your changes. Thanks
Screenshot 2023-01-20 at 10.22.43.png

 

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 ,
Jan 21, 2023 Jan 21, 2023

Copy link to clipboard

Copied

Looks good, but how well does it work on mobile?  And by mobile, do you mean the Adobe Mobile Reader?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Engaged ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

This one works well on mobile.

But if i use check boxes instead of radio buttons then i can't select only one option. After selecting option 1 i can select option 2 and 3 aswell. Once all 3 are selected, if i deselect option 1, then it will deselect all 3.

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
Engaged ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

I mean adobe mobile

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 ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

So, just to be clear, when you use checkboxes that are setup to be mutually exclusive (i.e. the checkbox fields all have the same name, but different exports), the behavior is mutually exclusive on the desktop Acrobat, but has the wierd non-exclusive behavior on the Mobile Acrobat? 

 

If true, then this is a bug in the mobile Acrobat Reader. There's nothing you can do to change it. 

Please post a bug report:

https://www.adobe.com/products/wishform.html

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Engaged ,
Feb 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

LATEST

ok

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