473,412 Members | 1,944 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,412 software developers and data experts.

Changing onkeypress behavior for field element

I can't find this anywhere, so I hope it can be done:
Here's what I can do so far:

1. Certain fields have a class 'textfield' while others are
'textfieldreq'.

2. OnSubmit checks all elements and makes sure that those with 'req'
have some value

3. It then sets the border on empty required fields to red

Now what I want to do is:

4. alter the onkeypress for the field

5. to restore the original class when someone enters something.

Can this be done?

Cheers!
Rick
Jul 20 '05 #1
1 2095
Rick Measham <ri***@spam.com.au> writes:
1. Certain fields have a class 'textfield' while others are
'textfieldreq'.

2. OnSubmit checks all elements and makes sure that those with 'req'
have some value

3. It then sets the border on empty required fields to red Now what I want to do is:

4. alter the onkeypress for the field
Use onchange instead. It is probably what you want.
5. to restore the original class when someone enters something.


You didn't say that you changed the class, only the border style.

Maybe something like this, in the code that recognizes empty fields:
---
badElement.style.border = "2px solid red"; // or whatever you do
badElement.onchange = function() { this.style.border="";
this.onchange=undefined; };
---
If you insist on using "onkeypress", change "onchange" to it

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

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

Similar topics

2
by: Joe | last post by:
having this script: ------------------------------------------------------------------- <script language="JavaScript" type="text/javascript"> <!-- function isanumber() { var antal =...
5
by: Albert Wagner | last post by:
I have included a file below that tests onKeyPress in Opera 7.11. I am getting peculiar behavior. When the file is first loaded, pressing the keypad + causes the textarea to get physically larger...
6
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a...
7
by: Kev | last post by:
I need to make some specific alterations to some JavaScript in webpages in order to comply with government guidelines on accessibility. Apparently, whenever the OnClick event is used, it must be...
2
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a...
2
by: Christopher Ambler | last post by:
I have a class that I deserialize into as such: public class row { public string RecordFound; public string IsExpired; }
1
by: Simon Wigzell | last post by:
I'm using a javascript function to interecept all key presses and check for valid character and also check the length of the current string and if it is greater than a sent value, set the focus to...
6
by: reynard | last post by:
I have a page that uses this doctype <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> but when I change to this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.