6 Replies Latest reply on Dec 20, 2006 5:40 PM by Dan Bracuk

    Textarea when Radio Button Clicked Yes

    smogcity2000
      I'm trying to add a textarea for a gift message if the users clicks the "Yes" radio button. The characters have to be limited to 150. I'm not a programmer and know very, very, little coldfusion. The message in the textarea will be stored in a pre-existing DB column.

      Any help with this is greatly appreciated.
        • 1. Re: Textarea when Radio Button Clicked Yes
          Charlie Griefer Level 1
          <input type="radio" name="giftMessage" value="1" onclick="textAreaShow('inline');" />Yes
          <input type="radio" name="giftMessage" value="0" onclick="textAreaShow('none');" />No

          <textarea name="giftMessageText" id="giftMessageText"></textarea>

          <script type="text/javascript">
          function textAreaShow(onOff) {
          document.getElementById('giftMessageText').style.display = onoff;
          }
          </script>

          for the text limit, that's a little tougher. textareas do not have the builtin maxlength attribute that text inputs have. there are javascripts you can use that will fire on the onkeyup event of the textarea counting the characters, but i personally don't care for those.

          i'd suggest on the submit action of the form, check the textarea.value length using JS and if it exceeds 150 characters, don't submit the form and alert the user. in addition, DEFINITELY check on the form's action page using CF to ensure that the length of the value passed is less than 150 (and if not, handle appropriately).
          • 2. Re: Textarea when Radio Button Clicked Yes
            smogcity2000 Level 1
            I just tried the code you provided and I don't think it works correctly.
            1. The textarea appears when page is loaded even when no button is checked.
            2. Nothing happens when either buttons are checked.

            What I would like is the Yes and No button to appear, No being checked, and yes bringing up the textarea.

            Another version is attached, however, not sure if the (value="#order_gift_Message#") value will pass if it's in the JS part of the code.
            • 3. Re: Textarea when Radio Button Clicked Yes
              Charlie Griefer Level 1
              ah, the problem in my code was cAsE-sEnSiTiViTy. fixed in the revision below, as well as hiding the textarea on the initial page load state.

              <input type="radio" name="giftMessage" value="1" onclick="textAreaShow('inline');" />Yes
              <input type="radio" name="giftMessage" value="0" onclick="textAreaShow('none');" />No

              <textarea name="giftMessageText" id="giftMessageText" style="display:none;"></textarea>

              <script type="text/javascript">
              function textAreaShow(onOff) {
              document.getElementById('giftMessageText').style.display = onOff;
              }
              </script>
              • 4. Re: Textarea when Radio Button Clicked Yes
                Dan Bracuk Level 5
                quote:

                Originally posted by: [CJ]
                <input type="radio" name="giftMessage" value="1" onclick="textAreaShow('inline');" />Yes
                <input type="radio" name="giftMessage" value="0" onclick="textAreaShow('none');" />No

                <textarea name="giftMessageText" id="giftMessageText"></textarea>

                <script type="text/javascript">
                function textAreaShow(onOff) {
                document.getElementById('giftMessageText').style.display = onoff;
                }
                </script>

                for the text limit, that's a little tougher. textareas do not have the builtin maxlength attribute that text inputs have.


                <cftextarea> has a maxlength attribute. I don't know if you can show and hide using your js, but it's worth a shot.

                • 5. Re: Textarea when Radio Button Clicked Yes
                  smogcity2000 Level 1
                  Dan, thank you very much for your help with this. Do you do freelance work at all?
                  • 6. Re: Textarea when Radio Button Clicked Yes
                    Dan Bracuk Level 5
                    quote:

                    Originally posted by: smogcity2000
                    Dan, thank you very much for your help with this. Do you do freelance work at all?

                    There are some rather clever people on this list who do. I am not one of them.