how to catch keystroke of enter key pressed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    how to catch keystroke of enter key pressed?

    hi all!

    for example;[enter] represents pressing enter key.
    i am typing "nirmal [enter] singh [enter] B"
    in a text area, so the result in textarea will be in three lines as follows.

    nirmal
    singh
    B

    while i get this data from textarea and save in database, i want to save something representing like enter key pressed or new line along with text. so that i can retrieve the record from database and show it in a same format as

    nirmal
    singh
    B

    how can i do this?

    thanx in advance.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by nirmalsingh
    hi all!

    for example;[enter] represents pressing enter key.
    i am typing "nirmal [enter] singh [enter] B"
    in a text area, so the result in textarea will be in three lines as follows.

    nirmal
    singh
    B

    while i get this data from textarea and save in database, i want to save something representing like enter key pressed or new line along with text. so that i can retrieve the record from database and show it in a same format as

    nirmal
    singh
    B

    how can i do this?

    thanx in advance.
    Now what's getting stored in DataBase?

    Debasis Jana

    Comment

    • nirmalsingh
      New Member
      • Sep 2006
      • 218

      #3
      Originally posted by dmjpro
      Now what's getting stored in DataBase?

      Debasis Jana
      while passing the value in query string using ajax to save it, the enter character is ignored and saved as a sequence sentence.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        hi ...

        you may use a regEx to prepare the value ... have a look at the following example:

        [CODE=html]<html>
        <head>
        <script type="text/javascript">

        function prepare_value() {
        var value = document.getEle mentById('text' ).value;

        value = value.replace(/(\n|\r\n)/g, '\n');

        alert(value);
        }

        </script>
        </head>
        <body>
        <form name="myform">
        <textarea id="text"></textarea>
        <input type="button" value="prepare" onclick="prepar e_value();">
        </form>
        </body>
        </html>
        [/CODE]
        kind regards

        Comment

        • nirmalsingh
          New Member
          • Sep 2006
          • 218

          #5
          Originally posted by gits
          hi ...

          you may use a regEx to prepare the value ... have a look at the following example:

          [CODE=html]<html>
          <head>
          <script type="text/javascript">

          function prepare_value() {
          var value = document.getEle mentById('text' ).value;

          value = value.replace(/(\n|\r\n)/g, '\n');

          alert(value);
          }

          </script>
          </head>
          <body>
          <form name="myform">
          <textarea id="text"></textarea>
          <input type="button" value="prepare" onclick="prepar e_value();">
          </form>
          </body>
          </html>
          [/CODE]
          kind regards
          yah it is working well as i wished format, but when i transfer that data to another page via querystring, all the datas are concatenated as nirmalsinghb
          what to do to solve this?

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by nirmalsingh
            yah it is working well as i wished format, but when i transfer that data to another page via querystring, all the datas are concatenated as nirmalsinghb
            what to do to solve this?
            You can use a special character and then replace it using your server side script.
            Mind it your special character should never occur in your Query String.

            Debasis Jana

            Comment

            • nirmalsingh
              New Member
              • Sep 2006
              • 218

              #7
              Originally posted by dmjpro
              You can use a special character and then replace it using your server side script.
              Mind it your special character should never occur in your Query String.

              Debasis Jana
              thank u jana i already tried it.
              but i replaced the character,'/n' by '~' but it is not replaced.

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                Originally posted by nirmalsingh
                thank u jana i already tried it.
                but i replaced the character,'/n' by '~' but it is not replaced.
                [code=javascript]
                var value = document.getEle mentById('text' ).value;
                value = value.replace(/(\n|\r\n)/g, '~');
                //now here prepare the query string ...............
                [/code]


                Debasis Jana

                Comment

                • nirmalsingh
                  New Member
                  • Sep 2006
                  • 218

                  #9
                  Originally posted by dmjpro
                  [code=javascript]
                  var value = document.getEle mentById('text' ).value;
                  value = value.replace(/(\n|\r\n)/g, '~');
                  //now here prepare the query string ...............
                  [/code]


                  Debasis Jana
                  thanx jana, its working perfectly.

                  Comment

                  Working...