9 Replies Latest reply on Mar 12, 2007 12:25 AM by Newsgroup_User

    disable enter

    craig_mac Level 1
      Hi i have a text area, which i need to stop users from using the enter key

      ie

      inside the text area the user can only use the spacebar and can NOT use the enter key to space out words

      how can this be done?
        • 1. Re: disable enter
          Level 7
          why do you want to prevent the use of Return/Enter key in your textarea?
          if it has to do with formatting of user's input for stroing/isplay, then
          there are other things you should be doing instead of disabling keys...
          otherwise, google for "javascript disable enter key" - you will have to
          write a js function to treat Enter/Return as a space inside your textarea
          --

          Azadi Saryev
          Sabai-dee.com
          http://www.sabai-dee.com
          • 2. Re: disable enter
            craig_mac Level 1
            ok the text area is a text area for sms text, if a user presses enter, the sms message gets cut off where the enter has been clicked.

            ie if a user types

            hello paul (enter)
            what wrong

            only the hello paul goes through

            so i need to stop the user from using the enter key inside the text box
            • 3. Re: disable enter
              Level 7
              i see..
              well, you can use Replace() function on the user's input string to
              replace all Chr(10) and Chr(13) with " " (space) before sending the
              sms... or use a regex:

              #REReplace(form.textareaname, "(Chr(13)|Chr(10))", " ", "ALL")#

              --

              Azadi Saryev
              Sabai-dee.com
              http://www.sabai-dee.com
              • 4. disable enter
                craig_mac Level 1
                ok thanks

                what is Chr(10) and Chr(13) ?

                does that = enter?

                if so how can i do the replace and then cfset a session.message
                • 5. Re: disable enter
                  Level 7
                  they are equivalents of CR and LF (carriage return and line feed)
                  characters - which is what pressing Return key inserts into the textarea
                  (depending on the operating system, either one of them or both)
                  --

                  Azadi Saryev
                  Sabai-dee.com
                  http://www.sabai-dee.com
                  • 6. Re: disable enter
                    craig_mac Level 1
                    Ok so if i use
                    #REReplace(form.textareaname, "(Chr(13)|Chr(10))", " ", "ALL")#

                    how do i set the new version without returns as a session
                    • 7. Re: disable enter
                      Level 7
                      if i understand you correctly:

                      you have a form where a user can type some text to send as sms;
                      lat's say that textarea in the form is named "smstext";
                      in the form's action page (in the code that processes form submission)
                      you will <cfset texttosend = REReplace(form.smstext,
                      "(Chr(13)|Chr(10))", " ", "ALL")>
                      so now the sms text without line feeds or carriage returns is stored in
                      the "texttosend" variable.

                      if you need to store that in the session scope, just do <cfset
                      session.texttosend = REReplace(form.smstext, "(Chr(13)|Chr(10))", " ",
                      "ALL")> instead.

                      you can use whatever valid variable name you want instead of "texttosend".
                      don't forget to use your actual textarea's name instead of "smstext".

                      --

                      Azadi Saryev
                      Sabai-dee.com
                      http://www.sabai-dee.com
                      • 8. Re: disable enter
                        craig_mac Level 1
                        ok i have tried that using this

                        <cfset texttosend = REReplace(form.message, "(Chr(13)|Chr(10))", " ", "ALL")>

                        then i inserted '#texttosend#' into a table in my database, but the enters still appear?

                        any ideas what i need to do
                        • 9. Re: disable enter
                          Level 7
                          craiglaw98 wrote:
                          > ok i have tried that using this
                          >
                          > <cfset texttosend = REReplace(form.message, "(Chr(13)|Chr(10))", " ", "ALL")>
                          >
                          > then i inserted '#texttosend#' into a table in my database, but the enters
                          > still appear?
                          >
                          > any ideas what i need to do
                          >

                          sorry, my fault. here's correct code:
                          <cfset texttosend = REReplace(form.message, "(#Chr(13)#|#Chr(10)#)", "
                          ", "ALL")>

                          ... i forgot the pound signes around Chr(xx)...

                          --

                          Azadi Saryev
                          Sabai-dee.com
                          http://www.sabai-dee.com