21 Replies Latest reply on Nov 5, 2012 3:09 PM by jpt999

    change value on checkbox

    jpt999 Level 1

      i have 5 radio button name as Rbutton have diffrent value

      1, 2, 3, 4, & 5.

       

      depends on user selection of Rbuttion i need change value in checkbox price.

       

      example if radio button Rbutton value 1 is selected by user then value of checkbox need to be change to 111.

      checkbox default value is 0

       

      if radio button Rbutton value 2 is selected by user then value of checkbox need to be change to 222...

        • 1. Re: change value on checkbox
          gkaiseril MVP & Adobe Community Professional

          Are you using LiveCycle Designer?

           

          I ask because the value for check boxes or radio buttons when not selected is the string "Off".

           

          You should be able to set the check box or radio button exclusionary group the the value of the button or box you want checked.

          • 2. Re: change value on checkbox
            jpt999 Level 1

            no i am using acrobat 9 trying to run javascript when user click on radio button then change the value of checkbox

            • 3. Re: change value on checkbox
              gkaiseril MVP & Adobe Community Professional

              The the value of the check box or radio button can not be zero.

              • 4. Re: change value on checkbox
                jpt999 Level 1

                ok. i can put checkbox default value is 1 but its need to be change when user selected radio button

                • 5. Re: change value on checkbox
                  gkaiseril MVP & Adobe Community Professional

                  With JavaScript in a PDF you can access a field's value, including a check box or radio button, or set the value of a field.

                   

                  You use the getField() to get a specific field object. You then need to specify the property or method for the field you want to access. For your task you want to use value property.

                   

                  So if you have two fields, MyRadioButton" and "MyCheckBox".

                   

                  "MyRadioButton" is a series of 5 fields each with the same name and each individual button has an button value of 1-5 with no individual button having the value an other button.

                   

                  "MyCheckBox" is series of 5 check boxes with the same name. The individual check boxes have an export value of 111, 222, 333, 444, or 555, and no check box has the value of any other check box.

                   

                  The value of "MyRadioButton" and "MyCheckBox" when no radio button or check box has been selected will be the string "Off".

                   

                  If you select one of the radio buttons, the value of "MyRadioButton" will become the value of the selected button. Based on that value you can set the value of the "MyCheckBox".

                   

                  For the "Mouse Up" action for all the "MyRadioButton" you can use the following JavaScript to set the value and select one of the "MyCheckBox" boxes.

                   

                  // get the value of the field "MyRadioButton"
                  var cSelect = this.getField("MyRadioButton").value;
                  var cSetValue = "Off"; // value for MyCheckBox
                  // select MyCheckBox value basee on "MyRadioButton" value
                  switch (cSelect) {
                  case 1:
                  cSetValue = 111;
                  break;

                  case 2:
                  cSetValue = 222;
                  break;

                  case 3:
                  cSetValue = 333;
                  break;

                  case 4:
                  cSetValue = 444;
                  break;

                  case 5:
                  cSetValue = 555;
                  break;
                  default:
                  cSetValue = "Off"; // value is no match above
                  }
                  // set the value and check "MyCheckBox"
                  this.getField("MyCheckBox").value = cSetValue;

                  • 6. Re: change value on checkbox
                    Mandeep5062 Employee Moderator

                    Please try the following :

                     

                    if (Radio_button1.rawValue == "1")

                    {

                    CheckBox1.rawValue = 1;

                    }

                    if (Radio_button2.rawValue=="1")

                    {

                    CheckBox2.rawValue =1;

                    }

                    • 7. Re: change value on checkbox
                      gkaiseril MVP & Adobe Community Professional

                      I an responding to the question using Acrobat Forms and not LiveCycle Desinger. There is documented "rawValue" property in Acrobat JavaScript.

                       

                      I would post a sample on Acrobat.com of the PDF form, but my account's files were removed and when I upload a form the form fields are removed.

                       

                      Working Example

                      • 8. Re: change value on checkbox
                        jpt999 Level 1

                        i added the code below on my radio button (tirgger mouse up run javascript.
                        i am able to select the radio button but when i select checkbox nothing happen i mean it wont check no way to see if value was change on checkbox price coz its not selected

                         

                        // get the value of the field "MyRadioButton"

                        var cSelect = this.getField("Rbutton ").value;

                        var cSetValue = "Off"; // value for MyCheckBox

                        // select MyCheckBox value basee on "MyRadioButton" value

                        switch (cSelect) {

                        case 1:

                        cSetValue = 111;

                        break;

                         

                        case 2:

                        cSetValue = 222;

                        break;

                         

                        case 3:

                        cSetValue = 333;

                        break;

                         

                        case 4:

                        cSetValue = 444;

                        break;

                         

                        case 5:

                        cSetValue = 555;

                        break;

                        default:

                        cSetValue = "Off"; // value is no match above

                        }

                        // set the value and check "MyCheckBox"

                        this.getField("price").value = cSetValue;

                        GKaiseril wrote:

                         

                        With JavaScript in a PDF you can access a field's value, including a check box or radio button, or set the value of a field.

                         

                        You use the getField() to get a specific field object. You then need to specify the property or method for the field you want to access. For your task you want to use value property.

                         

                        So if you have two fields, MyRadioButton" and "MyCheckBox".

                         

                        "MyRadioButton" is a series of 5 fields each with the same name and each individual button has an button value of 1-5 with no individual button having the value an other button.

                         

                        "MyCheckBox" is series of 5 check boxes with the same name. The individual check boxes have an export value of 111, 222, 333, 444, or 555, and no check box has the value of any other check box.

                         

                        The value of "MyRadioButton" and "MyCheckBox" when no radio button or check box has been selected will be the string "Off".

                         

                        If you select one of the radio buttons, the value of "MyRadioButton" will become the value of the selected button. Based on that value you can set the value of the "MyCheckBox".

                         

                        For the "Mouse Up" action for all the "MyRadioButton" you can use the following JavaScript to set the value and select one of the "MyCheckBox" boxes.

                         

                        // get the value of the field "MyRadioButton"
                        var cSelect = this.getField("MyRadioButton").value;
                        var cSetValue = "Off"; // value for MyCheckBox
                        // select MyCheckBox value basee on "MyRadioButton" value
                        switch (cSelect) {
                        case 1:
                        cSetValue = 111;
                        break;

                        case 2:
                        cSetValue = 222;
                        break;

                        case 3:
                        cSetValue = 333;
                        break;

                        case 4:
                        cSetValue = 444;
                        break;

                        case 5:
                        cSetValue = 555;
                        break;
                        default:
                        cSetValue = "Off"; // value is no match above
                        }
                        // set the value and check "MyCheckBox"
                        this.getField("MyCheckBox").value = cSetValue;

                        • 9. Re: change value on checkbox
                          gkaiseril MVP & Adobe Community Professional

                          Was the code added to every radio button named "Rbutton"?

                           

                          Are you getting any errors in the JavaScript Console of Acrobat?

                          • 10. Re: change value on checkbox
                            jpt999 Level 1

                            yes i have added the code in all 5 radio  button RButton.

                            i am not getting error check box value default wont change. see the screen shot

                             

                            Untitled-1.jpg

                            • 11. Re: change value on checkbox
                              gkaiseril MVP & Adobe Community Professional

                              A Jpeg does not let one see the code nor the relationships between the fields.

                               

                              Have you checked the calculation order of the form fields?

                              • 12. Re: change value on checkbox
                                Mandeep5062 Employee Moderator

                                Please see the attached Sample Form

                                • 13. Re: change value on checkbox
                                  jpt999 Level 1

                                  how can i include the pdf file on this form?

                                  • 14. Re: change value on checkbox
                                    jpt999 Level 1

                                    mandeep thanks for the sample but thats not what i am looking for.

                                    • 15. Re: change value on checkbox
                                      jpt999 Level 1

                                      yes i have checked calculation it just add using defaul value for checkbox.

                                      rbutton-javascript.jpgcheck-boxproperty.jpgtotal-calc.jpg

                                      • 16. Re: change value on checkbox
                                        gkaiseril MVP & Adobe Community Professional

                                        Do you want the check box or text field's value to change?

                                         

                                        You asked for selecting a check box based oh a radio button field's selection.

                                         

                                        If you look at the sample I provided, it also shows how to get a check box's and radio button's value to a text box. You would only need to adjust for a a value of "Off" to zero or a null string value.

                                        • 17. Re: change value on checkbox
                                          jpt999 Level 1

                                          i need checkbox value to be change based on a radio button selections

                                          text box is just caculating rbutton value & checkbox value.

                                          • 18. Re: change value on checkbox
                                            gkaiseril MVP & Adobe Community Professional

                                            I think the sample does what you described:

                                             

                                            NotSelected.jpg

                                             

                                            Selected.jpg

                                            • 19. Re: change value on checkbox
                                              jpt999 Level 1

                                              not sure why isnt working on my pdf form. cant upload the pdf file here.

                                              • 20. Re: change value on checkbox
                                                jpt999 Level 1

                                                gkaiseil,

                                                i am stuck . can i send you pdf form throught email. thanks.

                                                • 21. Re: change value on checkbox
                                                  jpt999 Level 1

                                                  still having no luck