Bosko
09-27-2002, 03:07 PM
What I need to do is add a tab character,\t, to a textarea when the user presses the Tab-key,instead of moving the focus to the next element.Fortunaly Konqueror already does this,so I only need to worry about Mozilla.Currently I have this code,which adds a tab character to the textarea,but the focus still moves to the address bar/body when I press the Tab-key:
<form>
<textarea id="textbox">arf!</textarea>
</form>
<script type="text/javascript">
function CatchTab(e){
if(e.keyCode==9){
document.getElementById("textbox").value=document.getElementById("textbox").value+"\t";
e.preventDefault();
e.stopPropagation();
}
document.getElementById("textbox").focus();
}
document.getElementById("textbox").addEventListener("keydown",CatchTab,true);
</script>
How can I prevent Mozilla from moving the focus to another element?
Thanks in advance for any help.
<form>
<textarea id="textbox">arf!</textarea>
</form>
<script type="text/javascript">
function CatchTab(e){
if(e.keyCode==9){
document.getElementById("textbox").value=document.getElementById("textbox").value+"\t";
e.preventDefault();
e.stopPropagation();
}
document.getElementById("textbox").focus();
}
document.getElementById("textbox").addEventListener("keydown",CatchTab,true);
</script>
How can I prevent Mozilla from moving the focus to another element?
Thanks in advance for any help.