Skip to main content
Known Participant
December 7, 2016
Answered

mulitple check boxes controling one text box. script trouble

  • December 7, 2016
  • 1 reply
  • 734 views

I asked a question yesterday about a single check box activating the border of a text box.  That question was answered perfectly and now I want to expand on that with 3 boxes.  sorry if a new post is not proper etiquette I'm new here, and the last one was marked answered.

the question I asked previously:  need to activate line with of a textbox with a checkbox.

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?

This topic has been closed for replies.
Correct answer gkaiseril

One can create a document level function like:

function AtLeastOne()

{

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

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

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

// using values and logical OR;

if(cb1 == 3 || cb2 == 3 || cb3 == 3)

{

     bord.lineWidth = 3;

     bord.display = display.visible;

}

else

{

     bord.display = display.hidden;

  }

return;

}

or

function AtLeastOne()

{

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

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

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

// using bitwise OR;

if (cb1 | cb2 | cb3 == 3)

{

     bord.lineWidth = 3;

     bord.display = display.visible;

}

else

{

     bord.display = display.hidden;

  }

return;

}

And then a mouse up action for each check box field:

AtLeastOne();

1 reply

Inspiring
December 7, 2016

You are using the bitwise Exclusive OR which returns true if one but not both options are true. Are you sure you want to use the XOR operator?

-trickAuthor
Known Participant
December 7, 2016

I want the text box to show a border if any combination of the boxes are checked.

I tried using the double pipe || but didn't work.

-trickAuthor
Known Participant
December 7, 2016

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