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

Trying to write javascript code to a check box that when it is checked, it removes the readonly attribute from another field and allows a number to be entered vs. the default calculation occurring.

New Here ,
May 17, 2016 May 17, 2016

I have an order entry form that calculates a markup $ amount by a formula in the simplified field notation section in the field properties of the calculate tab.  The Markup field is set to read only.  I also have a field setup as a check box.  If the user selects that check box, I need that markup field to become editable (remove the read only attribute) to allow a number to be entered in the field.  I am assuming I would also need to programmatically remove the calculation in the simplified field notation when the check box has been selected.  I am thinking I need a custom java script to trigger on mouse enter?  I also could use some help setting up the java script.  Has anyone every done something similar?

Thanks in advance.

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
Translate
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

Community Expert , May 17, 2016 May 17, 2016

You won't be able to use the "simple field notation" method anymore if you need to make the field editable in certain situations. The following script assumes that you just want to add up two fields and use 25% of that sum as your markup, unless the checkbox named "CheckBox" is checked, then the field will become editable, and you can enter anything you want:

// get the state of the "CheckBox" - modify the field name to match your form

var cb = this.getField("CheckBox");

if (cb.value == "Off") {

   

...
Translate
Community Expert ,
May 17, 2016 May 17, 2016

You won't be able to use the "simple field notation" method anymore if you need to make the field editable in certain situations. The following script assumes that you just want to add up two fields and use 25% of that sum as your markup, unless the checkbox named "CheckBox" is checked, then the field will become editable, and you can enter anything you want:

// get the state of the "CheckBox" - modify the field name to match your form

var cb = this.getField("CheckBox");

if (cb.value == "Off") {

    // Checkbox is unchecked, so perform the calculation and make sure the field is read-only

    event.target.readonly = true;

     // simple calculation - you need to modify this

    var result = (Number(this.getField("Field1").value) + Number(this.getField("Field2").value)) * 0.25;

    event.value = result;

}

else {

    // Checkbox is checked, so do not modify the value, set the field to read/write and let the user enter anything they want.

    event.target.readonly = false;

}

Translate
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 ,
May 18, 2016 May 18, 2016

Thanks for the code.  Would you enter this code in the custom calculation script or as an action in the markup field or the actual checkbox?  I really appreciate the help.

Translate
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 ,
May 18, 2016 May 18, 2016

Sorry, I should have clarified that: It's the custom calculation script of your result field.

Translate
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 ,
May 18, 2016 May 18, 2016
LATEST

Working perfectly now. Thank you for the help.

Translate
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