Expand my Community achievements bar.

How to create a conditional checkbox to output text

Avatar

Former Community Member

Hello,

I have an interesting situation, I have an interactive spreadsheet that has a clickbutton that will open outlook to email the form. It also creates a subject line to email based on fields in the pdf, I used the following code for that:

<script contentType="application/x-javascript">//Create a variable to hold the document  object

var oDoc = event.target;

oDoc.mailDoc({

bUI: true,

cTo: "a@b.com",

cSubject: Employee_Name.rawValue + ", " + Service_Area.rawValue + " ," + Employee_Number.rawValue  + " ," +  Dropdown1.rawValue

});

</script>

What I'd like to do to extend that is make it so if one of three checkboxes are clicked then it adds it to the email subject line eg.
[ ] A
[ ] B
[ ] C
If A = checked then D = "A"
else
if B = checked then D = "B"
else
if C = checked then D = "C"
-
cSubject: Employee_Name.rawValue + ", " + Service_Area.rawValue + " ," + Employee_Number.rawValue  + " ," +  Dropdown1.rawValue + " ," + D
-
So basically I want D to be some varible I add, how would you do this? Do I need to create something in the event part of the email form button or declare it elsewhere?
Thanks
3 Replies

Avatar

Level 9

Hi,

Are you sure that that will be CheckBox? As we can check more than one choice. But in the subject line you are using one variable i.e. "D".

However, if you want to check only one CheckBox and that's to be added do the subject line. Then try the following.

Create a hidden textfield. Say Hidden_Field. In the click or change event of the checkbox you have to write a bit of script so that it stores the choice in the hidden field and you can add the rawValue of the hidden field in the subject line.

In the Change or Click event of CheckBox .

If (this.rawValue == 1)

     {

          Hidden_Field.rawValue = "A";

     }

else

     {

          Hidden_Field.rawValue = null;

     }

Now replace the D in the subject line with Hidden_Field.rawValue ;

Thanks,

Bibhu.

Avatar

Former Community Member

Hi,

I tried creating a hidden text field in Acrobat Pro to feed a set of text based on which checkbox is clicked with the following example code:

(function () {

    // Get a reference to the text field

    var f = getField("bufferField");

    // Set the value of the text field

    if (event.target.value !== "Off") {

        f.value = "ABC"

    } else {

        f.value = "";

    }

})();

The issue is that I need to use livecycle to add the function I listed above to email it out with the subject feeding from the fields but once I import it into Livecycle the buffer field no longer works, it does not feed from the checkbox input anymore. Any reason why?

Avatar

Level 9

Hi,

I am a bit confused about the tool you are using to develop the form. Is it LiveCycle or Acrobat. LiveCycle's JavaScript is bit different than that of Acrobat's.

You can try the following script in LiveCycle in the check or click event of the check box.

var f = checkbox field name.rawValue ; // Stores the value of the check box, 1 = On, 0 = Off.

if (f == 0)

     {

          bufferField.rawValue = "ABC";

     }

else

     {

          bufferField.rawValue = "";

     }

Thanks,

Bibhu.