6 Replies Latest reply on Jun 9, 2010 2:28 PM by Shaun R

    Change value of text box on Mouse Up

    Shaun R

      newbie to javascript. I have a form with many checkboxes that need to be 4-cycle (Yes, No, Not Applicable, Blank) rather than 2 cycle so I went with a text box rather than a check box.

       

      Using a button and a text box, clicking the button cycles through all 4 values, placing them in the text box whose font is set to Wingdings2.  I would rather use just the text box and a Mouse Up action but I don't know how to write that code.

       

      This is what works for the button/text box combo:

       

      var t = this.getField("TextTest").value;

       

      switch(t) {

      case "":
      this.getField("TextTest").value = "P";
      break;

      case "P":
      this.getField("TextTest").value = "O";
      break;

      case "O":
      this.getField("TextTest").value = "X";
      break;

      case "X":
      this.getField("TextTest").value = "";

      }

       

      How can I do this with just the text box?  I would appreciate any help on this.  Also please let me know if I am setting myself up for future headaches doing it this way.

       

      Thanks

       

      Shaun

        • 1. Re: Change value of text box on Mouse Up
          MarkWalsh Level 4

          Why not just use a ComboBox?

          • 2. Re: Change value of text box on Mouse Up
            Shaun R Level 1

            Thanks Mark

            The desire was expressed for a check box. With the regular

            Acrobat check box being 2-cycle, I had to do something to make it 4-cycle.

            • 3. Re: Change value of text box on Mouse Up
              MarkWalsh Level 4

              If you need to use a checkbox, you can set up your checkboxes to use multiple values. Just create 4 checkboxes with the exact same name, and give each one a different export value.

              • 4. Re: Change value of text box on Mouse Up
                Shaun R Level 1

                Forgive my ignorance, but I envision 4 boxes in a row or a column for each check needed.  This form is 20 pages of checks, up to 30 per page.  Real estate wise, this wouldn't work.  Please correct me if I'm wrong.

                 

                I know I can set the value of another field, but can I set the value of a text box using a Javascript on it's MouseUp action?  If so, would you be so kind as to give me an example of that script.  Would it include commit or something?  Again, I am very new to javascript.  More used to VBA.

                 

                Cheers

                 

                Shaun

                • 5. Re: Change value of text box on Mouse Up
                  MarkWalsh Level 4

                  What you are trying to do can be done, just put the code in the mouseup of the text box. The problem is that when you mouse click on the text box, it becomes active. The script doesn't run until you exit the field, and it's a bit of an awkward interface.

                   

                  It's understandable that you don't want so many checkboxes, which is why I initially suggested using a ComboBox instead of a textbox. It's a standard interface element, and it allows the user to select the desired value from multiple choices (you have 3 plus 'Blank') instead of clicking to toggle through the different available values. You can also choose whether or not to allow the user to type a value not in the value list. It's also a lot easier to change if you need to update the value list. Plus, it works if the user doesn't have Javascript enabled.

                   

                  The following (slightly cleaner) code, however, will change the value in the textbox if you pu it in the mousup event if you do find the combobox not to your needs:


                  var t = event.target.value

                  switch(t) {

                  case "":
                  event.target.value = "P";
                  break;

                  case "P":
                  event.target.value = "O";
                  break;

                  case "O":
                  event.target.value = "X";
                  break;

                  default:

                  event.target.value = ""

                  }

                  • 6. Re: Change value of text box on Mouse Up
                    Shaun R Level 1

                    Thank you Mark.

                     

                    That code works well, although as you said it's a little cumbersome with having to tab out of the field to commit the value.

                     

                    Cheers