onkey event assistance please

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

    #1

    onkey event assistance please

    Hello - how would you put together a script that will detect if the
    character # is typed twice in a form, and then dosomething() ?

    Sincerely,

    Julia

  • Lee

    #2
    Re: onkey event assistance please

    Julia Briggs said:[color=blue]
    >
    >Hello - how would you put together a script that will detect if the
    >character # is typed twice in a form, and then dosomething() ?[/color]

    You probably don't want to do it by monitoring keystrokes.
    Do you mean twice within a particular form field?
    Here are two of many ways:

    <html>
    <head>
    <title>demo</title>
    <script type="text/javascript">
    function dosomething() {
    alert("dosometh ing");
    }
    function checkHash(field ) {
    if(-1!=field.value. search(/#.*#/)) {
    dosomething();
    return false;
    }
    }
    </script>
    </head>
    <body>
    <form onsubmit="retur n checkHash(iris) ">
    <input name="iris" onchange="check Hash(this)"><br >
    <input type="submit">
    </form>
    </body>
    </html>

    Comment

    • Julia Briggs

      #3
      Re: onkey event assistance please

      Hi there! Thanks for helping me with this. Yes, actually I need to
      run the something() event before the page is actually submitted, right
      at the moment the second # is pressed....How would that work?

      Comment

      • Lee

        #4
        Re: onkey event assistance please

        Julia Briggs said:[color=blue]
        >
        >Hi there! Thanks for helping me with this. Yes, actually I need to
        >run the something() event before the page is actually submitted, right
        >at the moment the second # is pressed....How would that work?[/color]

        It's almost always a bad idea to audit individual keystrokes,
        because people don't type perfectly. If they accidentally hit
        a second "#" and you fire off some action as they're hitting
        the backspace key, they're going to be annoyed.

        Both of the methods I posted check the value before anything is
        actually submitted. The onsubmit technique prevents submission
        if there is a second "#". Of course, you also need to audit on
        the server side, because some users may have scripting disabled.

        Comment

        • Julia Briggs

          #5
          Re: onkey event assistance please

          absolutely agree and understand -- this is a very unique project, where
          my requirements call for this kind of specific function, where the user
          will deliberately understand what is going on for this unique double
          hash keystroke. I am pretty sure this can be done with: if
          ((event.keyCode ) == #), but uncertain of its implementation here.

          Sincerely, Julie

          Comment

          Working...