Forum Moderators: open
I’ve got a textarea where people type in a description. However for certain reasons we need to stop them typing!$*^ .
I have a solution this which works fine in IE:
function keypress()
{
if((event.keyCode==33)¦¦(event.keyCode==36)¦¦(event.keyCode==42)¦¦(event.keyCode==94))
{
//bad key pressed
event.returnValue = false;
}
}
This function is in a javascript file and called from the textarea like this:
<textarea rows="13" maxLength="860" cols="30" name="remarks" id="remarks" title="description"
onchange="keypress();" onKeypress="keypress();" onKeyDown="keypress();" onKeyUp="keypress();"
value =""></textarea>
However, it doesn’t work in Firefox. I changed event.keyCode to event.which . However, this only works if the javascript is embedded in the html and not in my .js file. However, one of the requirements for my project is that it is W3c compliant and therefore the javascript should be in separate files and not embedded in the html.
Does anyone know how I can successfully get the event object in a javascript file using firefox so I can user event.which?
Cheers…Rich
;)
See the heading "Accessing the event" on this page:
[quirksmode.org...]
let us know if you need more help...