Hi
I have 2 small functions which are working fine in Safari and Firefox but not Internet Explorer. The functions count the characters in a text box and update a label which shows the total on each key press, including deletions.
I know that Char 8 is backspace but Internet Explorer doesn't seem to recognise it, so when you start deleting text in the box the label doesn't update until you press another key. I've tried show the key variable via alert to see what it is when backspace is pressed, but the alert window doesn't show.
Is there a way that I can get these functions to recognise the delete key in IE please? Here are the functions, and below these is the html code I'm using to call it.
Code:
function getKeyCode(e) {
if (window.event) { return window.event.keyCode; }
else if (e) { return e.which; }
else { return null; }
}
Code:
function verbatimMax(e, qVerb, max) {
if (max == 0 || max == '') { return true; }
var key, verbLength;
key = getKeyCode(e);
if (key == 8) {
verbLength = document.getElementById(qVerb).value.length - 1;
if (verbLength < 0) { verbLength = 0; }
document.getElementById('verbCharCount').innerHTML = 'Length: ' + verbLength + '/' + max;
return true;
}
if (key == null || key == 0 || key == 9 || key == 27) {
return true;
}
verbLength = document.getElementById(qVerb).value.length + 1;
if (verbLength > max) { return false; }
document.getElementById('verbCharCount').innerHTML = 'Length: ' + verbLength + '/' + max;
return true;
}
This is the onkeypress bit I have on the textarea tag:
Code:
onkeypress="return verbatimMax(event, 'Q16_VERBATIM', 400)"
Thanks
|