Capture Key, only allow numbers

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

    Capture Key, only allow numbers

    I have this function:

    function ValidateIntKey( )
    {
    var Key;
    var CharKey;
    Key = event.keyCode;
    alert(Key);

    //CharKey = String.charCode At(Key);
    alert(String.fr omCharCode(Key) );
    CharKey = String.fromChar Code(Key)
    if (!isInteger(Cha rKey))
    {
    alert("no integer");
    }
    }

    Where i have "alert("no integer");" i want to make the keyCode null so
    that it doesn't reach the textbox this function is attached to. How
    do i do this? I tried:

    event.keyCode = 0; but this did not work. Any other ideas?
  • Philip Ronan

    #2
    Re: Capture Key, only allow numbers

    On 1/10/04 6:41 pm, Leroy wrote:
    [color=blue]
    > I have this function:
    >
    > function ValidateIntKey( )
    > {
    > var Key;
    > var CharKey;
    > Key = event.keyCode;
    > alert(Key);
    >
    > //CharKey = String.charCode At(Key);
    > alert(String.fr omCharCode(Key) );
    > CharKey = String.fromChar Code(Key)
    > if (!isInteger(Cha rKey))
    > {
    > alert("no integer");
    > }
    > }
    >
    > Where i have "alert("no integer");" i want to make the keyCode null so
    > that it doesn't reach the textbox this function is attached to. How
    > do i do this? I tried:
    >
    > event.keyCode = 0; but this did not work. Any other ideas?[/color]

    Has it occurred to you that this function is going to annoy the crap out of
    everyone? We all make typing mistakes from time to time; that's why
    keyboards have a delete key. If your web page throws an alert at me every
    time I make a tiny slip of the finger then I'm not going to stay there very
    long.

    Why not do your form validation the old-fashioned way and check for integers
    in an onsubmit() event?

    Phil

    --
    Philip Ronan
    phil.ronanzzz@v irgin.net
    (Please remove the "z"s if replying by email)


    Comment

    • Lee

      #3
      Re: Capture Key, only allow numbers

      Philip Ronan said:[color=blue]
      >
      >On 1/10/04 6:41 pm, Leroy wrote:
      >[color=green]
      >> I have this function:
      >>
      >> function ValidateIntKey( )
      >> {
      >> var Key;
      >> var CharKey;
      >> Key = event.keyCode;
      >> alert(Key);
      >>
      >> //CharKey = String.charCode At(Key);
      >> alert(String.fr omCharCode(Key) );
      >> CharKey = String.fromChar Code(Key)
      >> if (!isInteger(Cha rKey))
      >> {
      >> alert("no integer");
      >> }
      >> }
      >>
      >> Where i have "alert("no integer");" i want to make the keyCode null so
      >> that it doesn't reach the textbox this function is attached to. How
      >> do i do this? I tried:
      >>
      >> event.keyCode = 0; but this did not work. Any other ideas?[/color]
      >
      >Has it occurred to you that this function is going to annoy the crap out of
      >everyone? We all make typing mistakes from time to time; that's why
      >keyboards have a delete key. If your web page throws an alert at me every
      >time I make a tiny slip of the finger then I'm not going to stay there very
      >long.
      >
      >Why not do your form validation the old-fashioned way and check for integers
      >in an onsubmit() event?[/color]

      Absolutely! Even if you do away with the alert and simply block
      all non-integer keystrokes, you're going to send people away angry.

      Imagine that I'm trying to type "123" and accidentally hit "12w".
      I may not even be looking at the screen when I realize that I've
      hit the wrong key and automatically hit the backspace. If you've
      blocked the "w" keystroke, I've just deleted the "2".

      Comment

      • Leroy Stanislowski

        #4
        Re: Capture Key, only allow numbers



        I am not looking for an analysis of what i am doing. I am just looking
        for an answer to my problem, please.

        I understand what everyone is saying about the annoyance, but i have a
        reason for doing this and it is not relevant to getting an answer to my
        problem.

        Can someone please tell me how i can intercept a keystroke an replace it
        with nothing? Thank you in advance

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Leroy Stanislowski

          #5
          Re: Capture Key, only allow numbers



          Found the answer.

          function ValidateIntKey( )
          {
          var Key;
          var CharKey;
          Key = event.keyCode;
          //alert(String.fr omCharCode(Key) );
          CharKey = String.fromChar Code(Key)
          if (!isInteger(Cha rKey))
          {
          event.returnVal ue = false;
          }
          }

          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Leroy Stanislowski

            #6
            Re: Capture Key, only allow numbers



            Found the answer.

            function ValidateIntKey( )
            {
            var Key;
            var CharKey;
            Key = event.keyCode;
            //alert(String.fr omCharCode(Key) );
            CharKey = String.fromChar Code(Key)
            if (!isInteger(Cha rKey))
            {
            event.returnVal ue = false;
            }
            }

            This only works on keypress, not keyup or keydown.

            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • Robert

              #7
              Re: Capture Key, only allow numbers

              In article <86ad932b.04100 10941.4bf0a4b0@ posting.google. com>,
              stanislowskilj@ intercim.com (Leroy) wrote:
              [color=blue]
              > I have this function:
              >
              > function ValidateIntKey( )
              > {
              > var Key;
              > var CharKey;
              > Key = event.keyCode;
              > alert(Key);
              >
              > //CharKey = String.charCode At(Key);
              > alert(String.fr omCharCode(Key) );
              > CharKey = String.fromChar Code(Key)
              > if (!isInteger(Cha rKey))
              > {
              > alert("no integer");
              > }
              > }
              >[/color]
              This is a feature of IE. When you do the alert, IE looses track of what
              key was pressed.

              Robert

              Comment

              • George Hester

                #8
                Re: Capture Key, only allow numbers

                "Leroy Stanislowski" <stanislowskilj @intercim.com> wrote in message news:415db28b$0 $26178$c397aba@ news.newsgroups .ws...[color=blue]
                >
                >
                > I am not looking for an analysis of what i am doing. I am just looking
                > for an answer to my problem, please.[/color]
                [color=blue]
                > *** Sent via Developersdex http://www.developersdex.com ***
                > Don't just participate in USENET...get rewarded for it![/color]

                Good luck Leroy

                --
                George Hester
                _______________ _______________ ____

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: Capture Key, only allow numbers

                  Leroy Stanislowski wrote:
                  [color=blue]
                  > I am not looking for an analysis of what i am doing. I am just looking
                  > for an answer to my problem, please.[/color]

                  Your problem is that you have not pressed the Power button
                  of the computer you are abusing. You're welcome.


                  PointedEars
                  --
                  Damnit Fraser! If you're gonna drop a guy, you gotta say something like
                  "Ray, I'm gonna drop ya."

                  Comment

                  • Randy Webb

                    #10
                    Re: Capture Key, only allow numbers

                    Thomas 'PointedEars' Lahn wrote:
                    [color=blue]
                    > Leroy Stanislowski wrote:
                    >
                    >[color=green]
                    >>I am not looking for an analysis of what i am doing. I am just looking
                    >>for an answer to my problem, please.[/color]
                    >
                    >
                    > Your problem is that you have not pressed the Power button
                    > of the computer you are abusing. You're welcome.[/color]

                    And to think it only took you 13 days to come up with that garbage. Wow.
                    You are starting to really impress me. Wanna buy some Ocean Front
                    property in Arizona? I have a deal just for you........

                    P.S. ExLax might be of help to you, since you are full of s**t.

                    --
                    Randy
                    comp.lang.javas cript FAQ - http://jibbering.com/faq

                    Comment

                    Working...