onkey event assistance please

J

Julia Briggs

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
 
L

Lee

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

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("dosomething");
}
function checkHash(field) {
if(-1!=field.value.search(/#.*#/)) {
dosomething();
return false;
}
}
</script>
</head>
<body>
<form onsubmit="return checkHash(iris)">
<input name="iris" onchange="checkHash(this)"><br>
<input type="submit">
</form>
</body>
</html>
 
J

Julia Briggs

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?
 
L

Lee

Julia Briggs said:
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?

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.
 
J

Julia Briggs

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top