10 Replies Latest reply on Apr 15, 2014 5:45 PM by CoryGSSI

    Adding Textbox Values to Array and Displaying them

    CoryGSSI

      Hey Guys,

       

      Im not that great at Javascript, and I am even less great with Adobe Standard, but I've been surfing for a few days through the threads hoping to find something that would work for me with a little editing, but either I am getting lost in some of the code, or there isnt anything that exactly fits what I am trying to do with forms... Let me try to explain it.

       

      I have 2 Rows of Text Boxes and a final textbox for output;

       

      The First row of text box is for the names of equipment, the second row is the quantity for each of those rows perspectively.

       

      I want to be able to do the following;

      If Quantity is greater than 0, I would like to be able to Apply the Name and quantity to an Array or set of arrays as needed

       

      Then in the third text box, I want to be able to Display the Contents of the arrays.

       

      For Example

      (Equipment Textboxes)               (Quantity Textboxes)

      Equip1                                          Quantity1

       

       

       

      (OutputText Box)

      Ladders    -     3

      Next Equip -  and Quantity

       

      I sort have come up with a basic code that somewhat works, but I dont think with my current work, that the format would allow for me to do the Quantity Check and only provide the Equipment that has a Quantity. Here is the code I have come up with.....

       

      var eQuipMent1 = this.getField("Equip1");
      var QuanTity1 = this.getField("Quantity1");
      var eQuipTotals = this.getField("EquipOutputBox");
      if (QuanTity1.value > 0) {
          three.value = eQuipMent1.value + "     " + QuanTity1.value + "\r\n " }
      }
      
      

       

      But like i said.. I dont think that would work out, and I am creating variables for each of the Equipment and Quantities, and I dont think that would work. I might be making this more complex than I mean to.

       

      Any help or advise is welcomed greatly!

       

      Thanks,

      Cory

        • 1. Re: Adding Textbox Values to Array and Displaying them
          CoryGSSI Level 1

          I've found a method that works, however it's still pretty long hand, but it works, However now the problem I am running in to is clearing the array of Products with Quantities. Using several methods seems to clear our the number of quantities and show 0 but I would much rather be able to clear the entire array, any suggestions?

          • 2. Re: Adding Textbox Values to Array and Displaying them
            CoryGSSI Level 1

            Below is the code I used to create the array and display it, which seems to work fine except for clearing the Array... Which I have tried several different methods (i.e. QuanArray = 0 on the reset switch) However it seems that none of these methods work effectively. Instead it just clears the Quantity portion of the array, but leaves all other parts of each index.

             


            // Create Array
            var QuanArray = new Array();
            // Equip1
            if (this.getField("Quantity1") > 0 ) ;
            {
            QuanArray[0] = this.getField("Equip1").value + " " + this.getField("Quantity1").value + "\r\n";
            }
            // Equip 2

            if (this.getField("Quantity2") > 0 ) ;
            {
            QuanArray[1] = this.getField("Equip2").value + " " + this.getField("Quantity2").value + "\r\n";
            }
            // Equip 3

            if (this.getField("Quantity3") > 0 ) ;
            {
            QuanArray[2] = this.getField("Equip3").value + " " + this.getField("Quantity3").value + "\r\n";
            }

            // Equip 4

            if (this.getField("Quantity4") > 0 ) ;
            {
            QuanArray[3] = this.getField("Equip4").value + " " + this.getField("Quantity4").value + "\r\n";
            }

            // Equip 5

            if (this.getField("Quantity5") > 0 ) ;
            {
            QuanArray[4] = this.getField("Equip5").value + " " + this.getField("Quantity5").value + "\r\n";
            }

            // Equip 6

            if (this.getField("Quantity6") > 0 ) ;
            {
            QuanArray[5] = this.getField("Equip6").value + " " + this.getField("Quantity6").value + "\r\n";
            }

            // Equip 7

            if (this.getField("Quantity7") > 0 ) ;
            {
            QuanArray[6] = this.getField("Equip7").value + " " + this.getField("Quantity7").value + "\r\n";
            }

            // Equip 8

            if (this.getField("Quantity8") > 0 ) ;
            {
            QuanArray[7] = this.getField("Equip8").value + " " + this.getField("Quantity8").value + "\r\n";
            }
            // Equip 9

            if (this.getField("Quantity9") > 0 ) ;
            {
            QuanArray[8] = this.getField("Equip9").value + " " + this.getField("Quantity9").value + "\r\n";
            }
            // Equip 10

            if (this.getField("Quantity10") > 0 ) ;
            {
            QuanArray[9] = this.getField("Equip10").value + " " + this.getField("Quantity10").value + "\r\n";
            }
            // Equip 11

            if (this.getField("Quantity11") > 0 ) ;
            {
            QuanArray[10] = this.getField("Equip11").value + " " + this.getField("Quantity11").value + "\r\n";
            }
            // Equip 12

            if (this.getField("Quantity12") > 0 ) ;
            {
            QuanArray[11] = this.getField("Equip12").value + " " + this.getField("Quantity12").value + "\r\n";
            }
            // Equip 13

            if (this.getField("Quantity13") > 0 ) ;
            {
            QuanArray[12] = this.getField("Equip13").value + " " + this.getField("Quantity13").value + "\r\n";
            }

            // Equip 14

            if (this.getField("Quantity14") > 0 ) ;
            {
            QuanArray[13] = this.getField("Equip14").value + " " + this.getField("Quantity14").value + "\r\n";
            }

            // Equip 15

            if (this.getField("Quantity15") > 0 ) ;
            {
            QuanArray[14] = this.getField("Equip15").value + " " + this.getField("Quantity15").value + "\r\n";
            }
            // Print out Array
            for ( i=0; i < QuanArray.length; i++ )
            {
            this.getField("Text7").value = QuanArray.toString();
            }

            I have another portion of a Dropdown box where I am trying to set up variables to print out the Name and Phone Number of a person after they are selected in the dropdown.. The problem is If I change from John to Jane, Janes Phone number is not changed.. Instead it will change the Name, but not the phone number.

             

             

             

            var SrName = this.getField("Dropdown17").value;
            var ContLine = "\r\n " + "Security Consultant \r\n " + "GUARDIAN SECURITY SYSTEMS, INC. \r\n " + "Direct phone number: ";
            var ConLine = this.getField("Text19");
            var SrContact = SrName + ContLine + SrPhone;
            ConLine.value = SrContact;

            //John Doe

            if (SrName = "John Doe") {

            SrPhone = "(555) 555-5555";

            }

            //Jane Doe

            if (SrName = "John Doe") {

            SrPhone = "(555) 555-5000";

            }

             

             

            Once again,

            Any help is appreciated.

            • 3. Re: Adding Textbox Values to Array and Displaying them
              try67 MVP & Adobe Community Professional

              Classic mistake. This:

              if (SrName = "John Doe") {

               

              Should be this:

              if (SrName == "John Doe") {

               

              The comparison operator in JS is either "==" or "===". Using "=" will assign the value on the right to the variable on the left.

              1 person found this helpful
              • 4. Re: Adding Textbox Values to Array and Displaying them
                CoryGSSI Level 1

                Thanks Gilad D,

                 

                That took care of my phone number issue, but still not sure about Clearing the QuanArray, Any clue? Odds are it is probably my Javascript syntax... xD

                • 5. Re: Adding Textbox Values to Array and Displaying them
                  try67 MVP & Adobe Community Professional

                  I'm not quite sure what you mean by "clearing the array"... When you define the variable you are in effect created an empty array, in this line:

                  var QuanArray = new Array();

                   

                  If you want to "clear" it later on, just re-use that line (only without the var command, since that variable already exists):

                   

                  QuanArray = new Array();

                  • 6. Re: Adding Textbox Values to Array and Displaying them
                    CoryGSSI Level 1

                    Yeah I tried this method, it must be something to do with my placement, I must be reassigning values somehow afterwards.

                    • 7. Re: Adding Textbox Values to Array and Displaying them
                      kecsushil

                      var SrName = this.getField("Dropdown17").value;
                      var ContLine = "\r\n " + "Security Consultant \r\n " + "GUARDIAN SECURITY SYSTEMS, INC. \r\n " + "Direct phone number: ";
                      var ConLine = this.getField("Text19");
                      var SrContact = SrName + ContLine + SrPhone;
                      ConLine.value = SrContact;

                       

                       

                      //John Doe

                      if (SrName = "John Doe") {

                      SrPhone = "(555) 555-5555";

                      }

                      //Jane Doe

                      if (SrName = "John Doe") {

                      SrPhone = "(555) 555-5000";

                      }

                       

                      First point - = should be ==

                      Second point - why you are comparing SrName twice  with the same name ("John Doe"). For Jane Doe, it should be compared with Jane Doe not with John Doe.

                       

                      I observed this, so I am replying. Might be you have the solution/figured out this change.

                      • 8. Re: Adding Textbox Values to Array and Displaying them
                        CoryGSSI Level 1

                        Thanks kecsushil,

                        the comparison operator was pointed out for me, thank you for pointing out the Jane Doe, I had changed it solely for posting on the website though, so it is not a part of my actualy script. They are different names on my script.

                        • 9. Re: Adding Textbox Values to Array and Displaying them
                          kecsushil Level 1

                          Did you find the solution?

                           

                          you can try below code to reset the array:

                          var j = 0;

                          while (QuanArray[j].value != null){

                          j = j+1;

                          }

                           

                          for (var i =0; i < j; i++){

                           

                          QuanArray[i].value = null ; // or '';

                           

                          }

                          • 10. Re: Adding Textbox Values to Array and Displaying them
                            CoryGSSI Level 1

                            I will check when I get home from work and let you know! I have not tried this method, but it looks promising!