[thelist] CAPS LOCK ON

Sam Carter scforum at iness.com
Tue Aug 31 15:03:33 CDT 2004


> 
> I found this:
> http://www.howtocreate.co.uk/jslibs/htmlhigh/capsDetect.html (JavaScript)
> http://www.developerfusion.com/show/267/ (VBScript)

I implemented the caps lock below from the first URL

var capsError = 'WARNING:\n\nCaps Lock is enabled\n\nThis field is case
sensitive';
function capsDetect( e ) {
	if( !e ) { e = window.event; } if( !e ) { MWJ_say_Caps( false );
return; }
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : (
e.charCode ? e.charCode : 0 ) );
	//was the shift key was pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) );
//bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check
if shift is pressed
	MWJ_say_Caps( ( theKey > 64 && theKey < 91 && !theShift ) || (
theKey > 96 && theKey < 123 && theShift ) );
}
function MWJ_say_Caps( oC ) {
	if( typeof( capsError ) == 'string' ) { if( oC ) { alert( capsError
); } } else { capsError( oC ); }
}

A very few of my customers complain that the code above creates POP-UPs when
CAPS LOCK is off and the SHIFT key is used.

If anyone has ideas on why this might be and how to correct the JavaScript,
please let me know.

There's the other possiblity that the 2nd URL above may have a better
technique.

Sam




More information about the thelist mailing list