4 Replies Latest reply on Mar 7, 2011 1:31 PM by RDformMan

    Copy value of text box if 'primary' text box is not null or " "

    RDformMan

      Hi -

       

      I have a form with text fields that should be echoed elsewhwere if and only if a primary text box is not null or " ".

       

      so txtPrimary, txtSecondary, txtDependant

       

      if primary is not "" or " " then take value of txtSecondary and set txtDependant to txtSeconadary.

       

      As this grows it may be that txtDependant will use txtSecondary if Primary not "" or " " otherwise txtDependancy will take take value from txtOther.

       

      Any direction/thoughts?

        • 1. Re: Copy value of text box if 'primary' text box is not null or " "
          George_Johnson MVP & Adobe Community Professional

          This may not be exactly what you want, but it's what you said you want. Use the following custom Calculate script for the txtDependancy field:

           

          // Custom Calculate script
          (function () {
          
              var f1 = getField("txtPrimary");
              var f2 = getField("txtSecondary");
          
              if (event.source && (event.source === f1 || event.source === f2)) {
          
                  v1 = f1.valueAsString;
                  v2 = f2.valueAsString;
          
                  if (v1 && v1 !== " ") {
                      event.value = v2;
                  } else {
                      // What should happen in this case?
                  }
              }
          
          })();
          

           

          Note that if the user enters something different in the txtDependent field, it will get set to the value of the txtSecondary field if the value of the txtPrimary or txtSecondary field changes. You didn't state what you want to happen to txtDependant if txtPrimary is blank or a single space.

          1 person found this helpful
          • 2. Re: Copy value of text box if 'primary' text box is not null or " "
            RDformMan Level 1

            Hi George -

             

            Thanks - I'm stuck.

             

            I have a form with a key field - if it has anything entered, certain other fields get one value, if not, they get another.

             

            My field is txtAgencyFEIN (primary). If this field has data, I need the company address populated. If not (no fein == no company [in my example!]) the person address gets populated. I need the address field txtAgencyBusinessAddress pulled into the business address if the FEIN is poulated (on the person address, I'll do similar calculations to determine the address value - if there is no FEIN, then use the txtBusinessAddress under the person section). The false case for each is that the calculating field is blank, empty or null.

             

            I tried this on the CALCtxtAgencyBusinessAddress field and nothing changed even when I had all four combinations of the two input fields (00, 01, 10, 11) -

             

            // Custom Calculate script
            (function () {

                var f1 = getField("txtAgencyFEIN");
                var f2 = getField("txtAgencyBusinessAddress");

                if (event.source && (event.source === f1 || event.source === f2)) {

                    v1 = f1.valueAsString;
                    v2 = f2.valueAsString;

                    if (v1 && v1 !== " ") {
                        event.value = "";
                    } else {
                       
                        event.value = v2;

                    }
                }

            })();

            • 3. Re: Copy value of text box if 'primary' text box is not null or " "
              George_Johnson MVP & Adobe Community Professional

              I'm not sure I follow all of that, but it seems like the script should be:

               

              // Custom Calculate script
              (function () {
              
                  var f1 = getField("txtAgencyFEIN");
                  var f2 = getField("txtAgencyBusinessAddress");
              
                  if (event.source && (event.source === f1 || event.source === f2)) {
              
                      var v1 = f1.valueAsString;
                      var v2 = f2.valueAsString;
              
                      if (v1 && v1 !== " ") {
                          event.value = v2;
                      } else {
                          event.value = "";
                      }
                  }
              
              })();
              
              • 4. Re: Copy value of text box if 'primary' text box is not null or " "
                RDformMan Level 1

                George -

                 

                You followed it very well - it works as desired (it would have helped if I had turned on javascript debugging a little earlier, as I was setting v2 to an improperly named source field (txtAgencyBusinessAddr is correct and I was trying txtAgencyBusinessAddress).

                 

                Thank you - I can move on to other parts of my monster now.