I am trying to catch the return key and the tab key when inside a CE. I want to tab to the next form field when the user uses the tab key; I don't want to insert spaces. I also want to catch the return character and not allow them to hit return.
I am trying to follow the following article you had presented to me previously...
That example only works sometimes. It is really hoaky. Sometimes it works and sometimes it doesn't. Sometimes attaching events to a CE won't work unless you refresh the page. Is this a bug?
My situation is that I want to attach multiple events to a CE. Can this be done? I already have a blur event attached to my CE, so would that be conflicting with a keypress event?
The following code should catch a return character and cancel it. It should also put focus onto the subject field in the form when it recieves a tab key event. Neither work. Here is my code.
<script language="javascript">
<!--
function attachTabEvent()
{
//alert('attaching tab event');
// get the cute editor instance
var editor1 = document.getElementById('CE_txtTo_ID');
//Get the editor content
var editdoc=editor1.GetDocument();
// attach Event
if(editdoc.attachEvent)
editdoc.attachEvent('onkeypress',CheckTabKey);
else if(editdoc.addEventListener)
editdoc.addEventListener('keypress',CheckTabKey,true);
//alert('done attaching');
}
function CheckTabKey(event){
//alert(event.keyCode);
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
//alert(keyCode);
if(keyCode==13){
alert('return');
event.returnValue=false;
event.cancel = true;
} else {
alert(event.keyCode);
}
if(keyCode==9){
MoveToSubjectField();
}
}
function MoveToSubjectField(){
alert('in subject move');
var SubjectField = window.document.getElementById('txtSubject')
SubjectField.focus();
}
// Attach the Tab Event to the CE
setTimeout('attachTabEvent();',1000);
//-->
</script>