3 Replies Latest reply on Feb 2, 2016 9:23 AM by NHJB MHP

    Pull document level javascript

    NHJB MHP

      I have a working JavaScript (below) but, because it will ultimately affect 9 fields, it will get very long.  The changes in a text field are triggered by whether a check box is checked or not so currently the JavaScript is in the Mouse Up Action of the check box. I assume a Doc Level is more efficient? I have other Doc Level scripts which are contained within 1 field but since this is triggered by the check box I expect I need a different method. I have a Reset Button on the form which would also need the ability to reset those specific fields.

       

      Working JavaScript in Mouse Up Action of check box:

      var r = getField("cb7");
      var s = getField("III.A.3");

       

      if (r.type === "checkbox" && r.value == "additional victims on page 2") {
      s.readonly = false;
      s.required = true;
      s.fillColor=["G",.8];
      s.value = "";

      }

      else

      if (r.type === "checkbox" && r.value != "additional victims on page 2"){
      s.readonly = true;
      s.required = false;
      s.fillColor=color.transparent;
      s.value = "";

      }

       

      Thanks

      Meabh

        • 1. Re: Pull document level javascript
          frameexpert Level 4

          For document-level JavaScripts, it is best to organize them into functions.

           

          function myFunction1 () {

            // function code here.

          }

           

          function myFunction2 () {

            // function code here.

          }

           

          Then in your form fields' JavaScript, you can simply call the appropriate function:

           

          myFunction1 ();

           

          I hope this helps. -Rick

          • 2. Re: Pull document level javascript
            NHJB MHP Level 1

            I had the thought of using an Array for the text field name and pull the function that way.  I used 'required' as the Array name, changed all the text field names to start with 'required' with this code as a Doc Level and required(event.target.name) in the check box Action. Still no joy.

             

            function required(fieldName){
            var r = getField("cb7");
            var s = getField(required);

             

            if (r.type === "checkbox" && r.value == "additional victims on page 2") {
            s.readonly = false;
            s.required = true;
            s.value = "";


            }

            else

            if (r.type === "checkbox" && r.value == "additional victims on page 2") {
            s.readonly = true;
            s.required = false;
            s.value = "";


            }

            else
            {
            s.readonly = true;
            s.required = false;
            s.value = "";
            }
            }

            • 3. Re: Pull document level javascript
              NHJB MHP Level 1

              The eagle eyed experts no doubt would have noticed the lack of "" that should be with the field name 'required' a lot sooner than I did but with that little addition this works!!