By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,322 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

onkey event assistance please

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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>

Jul 23 '05 #2

P: n/a
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?

Jul 23 '05 #3

P: n/a
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.

Jul 23 '05 #4

P: n/a
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

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.