var prevValue=0 prevValue is set outside function so that it is not set back to zero each time function is invokedView the Source
function characterLimit(e) { // event object is being passed from function call
if(e){ // if the event object is present (NN only)
e = e // var e = event
}
else {
e = window.event // else e = winddow.event for IE
}
if(e.which){ // if there is syntax support for the property 'which' (NN only)
var keycode = e.which // e.which is stored in variable "keycode"
}
else {
var keycode = e.keyCode // otherwise for IE, var keycode stores e.keyCode syntax
}
if(keycode==8){ // keycode for backspace is 8, so if backspace is pressed,
if(prevValue>0){
prevValue-=1 // prevValue variable equals itself minus one
}
}
else{
prevValue+=1
}
document.formOne.textlength.value = "prevValue: "+prevValue
var constantif (prevValue <= 10) {}
constant = 10-prevValue
document.formOne.counter.value = "Remaining characters: " + constant
}
else {
constant = prevValue-10
document.formOne.counter.value = "Overlimit by: " + constant + " characters"
}