(event.keyCode==8) BACKSPACE problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Julia Briggs

    #1

    (event.keyCode==8) BACKSPACE problems

    Are there any gotchas using if (event.keyCode= =8)? I understand that
    to represent backspace, but it doesn't work. I am running Windows XP,
    using a typical keyboard - but no luck in detecting backspaces. Anyone
    have experiences with this?

  • Evertjan.

    #2
    Re: (event.keyCode= =8) BACKSPACE problems

    Julia Briggs wrote on 21 mrt 2005 in comp.lang.javas cript:
    [color=blue]
    > Are there any gotchas using if (event.keyCode= =8)? I understand that
    > to represent backspace, but it doesn't work. I am running Windows XP,
    > using a typical keyboard - but no luck in detecting backspaces. Anyone
    > have experiences with this?[/color]

    Unless an <input> field is in focus,
    BS is a reserved key for one page back.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)

    Comment

    • Julia Briggs

      #3
      Re: (event.keyCode= =8) BACKSPACE problems

      Ah! I (think) I am following you. When I say backspace, I actually
      mean the delete key. How would you replace in your snippet below to
      detect a single delete and then dosomething(). I *really* appreciate
      your time.

      %Julia%


      <script type='text/javascript'>

      var n=0


      function x(){
      if(event.keyCod e==35){
      n+=1
      if (n==2)alert('2 x #')
      }

      }


      </script>

      <input onkeypress='x() '>

      Comment

      • RobG

        #4
        Re: (event.keyCode= =8) BACKSPACE problems

        Julia Briggs wrote:[color=blue]
        > Ah! I (think) I am following you. When I say backspace, I actually
        > mean the delete key. How would you replace in your snippet below to
        > detect a single delete and then dosomething(). I *really* appreciate
        > your time.[/color]

        This will help you work out keyCodes (it also works in more
        browsers than just IE):

        <script type="text/javascript">
        function sayKeyCode(even t, v){
        document.getEle mentById(String (event.type)).i nnerHTML =
        'Value on ' + event.type + ': ' + v
        + ' KeyCode: ' + event.keyCode;
        }
        </script>

        <input type="text" size="10"
        onkeyup="sayKey Code(event,this .value);"
        onkeydown="sayK eyCode(event,th is.value);"><br >
        <span id="keydown"></span><br>
        <span id="keyup"></span>



        'Delete' is keyCode 46.

        If you want to intercept the key before anything happens, use
        onkeydown. If you want to do something after the key has done
        whatever to the field, use onkeyup.

        [...][color=blue]
        >
        > function x(){[/color]

        Need to capture event (see below):

        function x(event){
        [color=blue]
        > if(event.keyCod e==35){
        > n+=1
        > if (n==2)alert('2 x #')
        > }[/color]
        [...][color=blue]
        >
        > <input onkeypress='x() '>[/color]

        If you don't pass 'event', it will not work in Firefox

        <input onkeypress='x(e vent)'

        Passing 'event' does not affect IE, it just adds support for
        those browsers that support the alternative Mozilla event model.


        --
        Rob

        Comment

        • Evertjan.

          #5
          Re: (event.keyCode= =8) BACKSPACE problems

          Julia Briggs wrote on 21 mrt 2005 in comp.lang.javas cript:
          [color=blue]
          > Ah! I (think) I am following you.[/color]

          Well we cannot follow you if you don't quote, Julia.

          This is not email but usenet, so follow netiquette.
          [color=blue]
          > When I say backspace, I actually mean the delete key.[/color]

          Please say what you mean.
          Programming is a strict technology.

          --
          Evertjan.
          The Netherlands.
          (Replace all crosses with dots in my emailaddress)

          Comment

          • Evertjan.

            #6
            Re: (event.keyCode= =8) BACKSPACE problems

            Evertjan. wrote on 21 mrt 2005 in comp.lang.javas cript:
            [color=blue]
            > Julia Briggs wrote on 21 mrt 2005 in comp.lang.javas cript:
            >[color=green]
            >> Ah! I (think) I am following you.[/color]
            >
            > Well we cannot follow you if you don't quote, Julia.
            >
            > This is not email but usenet, so follow netiquette.[/color]

            I take this back/I delete this.
            The bottom part of your message, seems to be the quote.
            [color=blue][color=green]
            >> When I say backspace, I actually mean the delete key.[/color]
            >
            > Please say what you mean.
            > Programming is a strict technology.
            >[/color]

            RobG already informed you on the delete keycode,
            and mark his response style.


            --
            Evertjan.
            The Netherlands.
            (Replace all crosses with dots in my emailaddress)

            Comment

            • Julia Briggs

              #7
              Re: (event.keyCode= =8) BACKSPACE problems

              Hi there. Thank you for your original solution (which worked for me).
              My new problem is trying to get it to detect the keyboard backspace
              key. I made a mistake calling it a delete key.

              You mentioned "Unless an <input> field is in focus, BS is a reserved
              key for one page back.", which clues me in to this issue. How/what does
              this work in this situation? Could you please show an example?

              Sincerely, Julia.

              Comment

              • Evertjan.

                #8
                Re: (event.keyCode= =8) BACKSPACE problems

                Julia Briggs wrote on 21 mrt 2005 in comp.lang.javas cript:
                [color=blue]
                > Hi there. Thank you for your original solution (which worked for me).
                > My new problem is trying to get it to detect the keyboard backspace
                > key. I made a mistake calling it a delete key.
                >
                > You mentioned "Unless an <input> field is in focus, BS is a reserved
                > key for one page back.", which clues me in to this issue. How/what does
                > this work in this situation? Could you please show an example?
                >
                > Sincerely, Julia.
                >[/color]

                Dear Julia,

                This is usenet, not email.

                Others want to read and possibly comment too.

                So if you persist in not(!) quoting relevant part
                of the posting you reply upon
                that is considered rude to the NG community.

                If you don't conform to this 20 year old netiquette/custom,
                I won't reply to your questions.

                --
                Evertjan.
                The Netherlands.
                (Replace all crosses with dots in my emailaddress)

                Comment

                • Julia Briggs

                  #9
                  Re: (event.keyCode= =8) BACKSPACE problems

                  Hi there. Thank you for your original solution (which worked for me).
                  My new problem is trying to get it to detect the keyboard backspace
                  key. I made a mistake calling it a delete key.

                  You mentioned "Unless an <input> field is in focus, BS is a reserved
                  key for one page back.", which clues me in to this issue. How/what does

                  this work in this situation? Could you please show an example?

                  Sincerely, Julia.

                  (Sorry Evertjan, I will work on that. Thank you for the Netiquette
                  lesson.)

                  Comment

                  • RobG

                    #10
                    Re: (event.keyCode= =8) BACKSPACE problems

                    Julia Briggs wrote:[color=blue]
                    > Hi there. Thank you for your original solution (which worked for me).
                    > My new problem is trying to get it to detect the keyboard backspace
                    > key. I made a mistake calling it a delete key.[/color]

                    'it' being an input field? The document body?

                    The code snippet I posted earlier gives you an input that
                    reports the keyCode of whatever key is pressed. Use it to find
                    out what the keyCode is for any key pressed.

                    If you want to detect 'backspace' anywhere in the document, use
                    an onkeydown event with the body element to capture it.
                    [color=blue]
                    >
                    > You mentioned "Unless an <input> field is in focus, BS is a reserved
                    > key for one page back.", which clues me in to this issue. How/what does
                    > this work in this situation? Could you please show an example?[/color]

                    In what situation? If an input is in focus, the backspace key
                    will be passed to the input form control, which will delete a
                    character if there is one immediately before the current cursor
                    position, or do nothing if not.

                    If an input or textarea or some other editable element is not in
                    focus, the browser will capture the keydown and *maybe* navigate
                    back to the previous history entry if there is one. If there
                    isn't one, it wont.
                    [color=blue]
                    >
                    > Sincerely, Julia.
                    >
                    > (Sorry Evertjan, I will work on that. Thank you for the Netiquette
                    > lesson.)
                    >[/color]

                    Actions speak louder than text?


                    --
                    Rob

                    Comment

                    • Julia Briggs

                      #11
                      Re: (event.keyCode= =8) BACKSPACE problems

                      Thanks Rob for the gang-up. Did you get my e-mail thanking you earlier
                      or did Google not send it to you? ...............

                      Comment

                      • RobG

                        #12
                        Re: (event.keyCode= =8) BACKSPACE problems

                        Julia Briggs wrote:[color=blue]
                        > Thanks Rob for the gang-up. Did you get my e-mail thanking you earlier
                        > or did Google not send it to you? ...............
                        >[/color]

                        It is usual to reply via the newsgroup unless specifically asked
                        to respond with email. The idea of the group is that many people
                        can view posts, which is useful for learning and also posting
                        responses.

                        The group FAQ is here:

                        <URL:http://www.jibbering.c om/faq/>

                        Please read #2.3 in particular.

                        Having been around this group for a little while, you will have
                        read through a number of threads and can see the style of
                        response that is preferred and how various posters add to the
                        knowledge passed on by previous posters by offering
                        improvements, alternatives and corrections.

                        If you annoy participants by not following established group
                        etiquette, they will stop responding to or even reading your
                        posts. Most newsreaders can be set to ignore posts from certain
                        users so that their posts don't appear at all.

                        The group's guidelines are pretty much the same as those that
                        have been established by news group users in general over many
                        decades and are fundamental to the smooth running of the group.
                        Deliberately ignoring them means that you don’t value the
                        opinion of the people who developed them (i.e. the participants
                        in the group).

                        If you don’t value their opinion or respond to their (quite
                        reasonable) requests to follow the group etiquette when posting,
                        why should they answer your questions?


                        --
                        Rob

                        Comment

                        • Julia Briggs

                          #13
                          Re: (event.keyCode= =8) BACKSPACE problems

                          Uh, thanks for that response.... but isn't the spirit of this group to
                          help people who are in need, from people more knowledgeable, ....... so
                          then why are you standing on a soapbox quoting etiquette and acting
                          like a complete ass???? My approach from start one was genuine. I am
                          sorry I didn't include the original quote in my earlier response. But
                          I digress........ I think you are absolutely and hopelessly lost
                          responding to my words on the screen and not taking it light,
                          misunderstandin g them as you are. That is one tip for life. Maybe you
                          don't care to think it's important, but who cares anyway huh?

                          Anyway.

                          Comment

                          • Mick White

                            #14
                            Re: (event.keyCode= =8) BACKSPACE problems

                            Julia Briggs wrote:[color=blue]
                            > Uh, thanks for that response.... but isn't the spirit of this group to
                            > help people who are in need, from people more knowledgeable, ....... so
                            > then why are you standing on a soapbox quoting etiquette and acting
                            > like a complete ass???? My approach from start one was genuine. I am
                            > sorry I didn't include the original quote in my earlier response. But
                            > I digress........ I think you are absolutely and hopelessly lost
                            > responding to my words on the screen and not taking it light,
                            > misunderstandin g them as you are. That is one tip for life. Maybe you
                            > don't care to think it's important, but who cares anyway huh?
                            >
                            > Anyway.
                            >[/color]

                            You did it again!!!
                            Mick

                            Comment

                            • Dr John Stockton

                              #15
                              Re: (event.keyCode= =8) BACKSPACE problems


                              Keith Thompson wrote in comp.lang.c, message ID
                              <lnwtuhfy7d.fsf @nuthaus.mib.or g> :-
                              If you want to post a followup via groups.google.c om, don't use
                              the "Reply" link at the bottom of the article. Click on "show options"
                              at the top of the article, then click on the "Reply" at the bottom of
                              the article headers.

                              --
                              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
                              Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
                              Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
                              No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                              Comment

                              Working...