473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Detecting keystorokes that "matter"

I have a form on a web page that contains several textbox controls (i.e.
input type="text") and a checkbox. As soon as the text changes, in only a
subset of these textbox controls, I want to enable the checkbox. I've tried
the OnChange event for these textbox controls, but this event is fired only
when the control loses focus. I need the checkbox to enable immediately. I
then started experimenting with the OnKeyUp event for these controls, and it
works but it picks up many keystrokes that really don't matter (e.g. Tab,
Esc, Shift). In othe words, I am only concerned with keystrokes that can
actually change the text in the control.

I tried filtering by key code and only considering codes between 32 and 127,
inclusive, and 8 (for the back space key), but this still picks up keys like
the left arrow. In this case, the keycode appears to be 37 which is the %
character. I'm not sure why this is.

In any case, I don't have to take this OnKeyUp type of approach if someone
has a better technique. In the end, I just want to enable a checkbox as
soon as text starts to change in one of these controls. Any help on
accomplishing this would be greatly appreciated.

Thanks!
Jul 23 '05 #1
2 1220
VK
> In the end, I just want to enable a checkbox as
soon as text starts to change in one of these controls. Any help on
accomplishing this would be greatly appreciated.


I'm not sure what exact rules are, you may change this script to make
it more narrow.

<html>
<head>
<title>Keystokes</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function test(box) {
if(!box.memory) {
box.memory = "";
};
if ((box.value != box.memory)||(box.value != "")) {
alert("Text changed");
}
else {
alert("Test did not change");
}
}
</script>
</head>

<body bgcolor="#FFFFFF">
<form method="post" action="">
<input type="text" name="textfield1" onkeyup="test(this)">
</form>
</body>
</html>

Jul 23 '05 #2
Lee
epigram said:

I have a form on a web page that contains several textbox controls (i.e.
input type="text") and a checkbox. As soon as the text changes, in only a
subset of these textbox controls, I want to enable the checkbox. I've tried
the OnChange event for these textbox controls, but this event is fired only
when the control loses focus. I need the checkbox to enable immediately.


You're going to a lot of trouble and adding potential sources of
error to your page because you believe that you need the checkbox
to enable immediately. I would start by revisiting that idea.

It would be much easier (and safer) to leave the checkboxes enabled.
Your server-side code is going to be smart enough to ignore any
checkboxes corresponding to empty fields, isn't it?

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
5
by: Alf P. Steinbach | last post by:
Thanks to a new version of OpenOffice that produces acceptable (although not yet perfect) PDF, and numerous requests for PDF format, I've now made chapter 2.1 available in PDF format -- e.g., use...
24
by: hjbortol | last post by:
Hi! Is the expression "a >= b" equivalent to "a - b >= 0" in C/C++? Is this equivalence an IEEE/ANSI rule? Or is this machine/compiler dependent? Any references are welcome! Thanks in...
11
by: Matt Kruse | last post by:
This is a common requirement - "freeze panes" in a table, so that some header rows and some columns on the left are frozen while the body content scrolls. This makes large tables more usable on...
72
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
10
by: petermichaux | last post by:
Hi, I'm picking apart the Yahoo! UI event.js library and stripping it down to just what I need. I'm also trying to make the parts I use better. I'm stumped on how to fix the code for the...
5
by: Don A. Gomez | last post by:
I want to write a "Gaydar" software in C++, so that I can have a mobile computer system calculate the gayness of the men I encounter. This does require a very sophisticated program code, a...
92
by: ureuffyrtu955 | last post by:
Python is a good programming language, but "Python" is not a good name. First, python also means snake, Monty Python. If we search "python" in google, emule, many results are not programming...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.