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

need to activate line with of a textbox with a checkbox.

New Here ,
Dec 06, 2016 Dec 06, 2016

I'm trying to make a pdf that when you check certain boxes a section of the doc will highlight.

I thought the best way to go about it is to use the lineWidth of a text box.  Not sure if that IS the best way it was just a thought...

But I want to border to be hidden first then when a checkbox is checked it will be visible.  if the box is unchecked it goes back to hidden.

I've tried this in the checkbox action:

var checkBox1 = getField("CheckBox1").value;

var bord = getField("bordr1");

bord.lineWidth = 0;

if (checkBox1 = "Yes") {

    bord.lineWidth = 3;

}

else {

    bord.lineWidth = 0;

}

but it doesn't work.  couple questions

is there a way to just write code instead of putting it in actions?

if not how can I hide the text box by default?  and still be able to display it later?

TOPICS
Acrobat SDK and JavaScript
857
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 , Dec 06, 2016 Dec 06, 2016

Remove line #3 from your code.

Also, you used the wrong operator in line #5. It should be:

if (checkBox1 == "Yes") {

Regarding the execution of the code: It can be done from several places. For testing purposes you can run it from the JS Console.

Press Ctrl+J to open it, then paste the code into it, select ​all of it using the mouse or keyboard and press Ctrl+Enter to run it.

Translate
Community Expert ,
Dec 06, 2016 Dec 06, 2016

Remove line #3 from your code.

Also, you used the wrong operator in line #5. It should be:

if (checkBox1 == "Yes") {

Regarding the execution of the code: It can be done from several places. For testing purposes you can run it from the JS Console.

Press Ctrl+J to open it, then paste the code into it, select ​all of it using the mouse or keyboard and press Ctrl+Enter to run it.

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 ,
Dec 07, 2016 Dec 07, 2016

Thank you!  That worked as I wanted it to. 

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 ,
Dec 07, 2016 Dec 07, 2016

So.  now that is working I tried to translate to multiple checkboxes.

Basically I have three checkboxes and if any of them are checked then I want the box to show the border.  I'm still trying to type the code in the properties -> actions area since the "All javascript" part adds XML that I'm not exactly sure what its used for so I don't want to change it or create something without it...   Basically I'm typing the below code into the actions of each checkbox which seems redundant but I don't know any other way to do it.  The console is great when trying things out but what do I do when I want to send this PDF to someone?  other than actions where does the code go?

so, anyway, here is the code I'm trying.  ( I DID change the value in each check box from "Yes" to "3")

var cb1 = getField("CheckBox1").value;

var cb2 = getField("CheckBox2").value;

var cb3 = getField("CheckBox3").value;

var bord = getField("bordr1");

if (cb1 ^ cb2 ^ cb3 == "3") {

    bord.lineWidth = 3;

    bord.display = display.visible;

}

else {

    bord.display = display.hidden;

}

this works to a point.  I can check each box individually and get the border.  I can check the "first and third", and the "second and third" but when I check the "first and second" the border turns back off when the second box is checked.  I'm confused as to why this is happening,  Any thoughts? 

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 ,
Dec 07, 2016 Dec 07, 2016

What did you try to express with this symbol "^"?

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
LEGEND ,
Dec 07, 2016 Dec 07, 2016

That is the Exclusive OR bitwise operator.

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 ,
Dec 07, 2016 Dec 07, 2016
LATEST

ok well...  A single pipe seems to work.  For some reason I was reading that the standard or operator was a double pipe.  this is all pretty new to me still.

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