Entry
Change from Edit mode to Insert mode without pressing Insert key
Aug 11th, 2006 15:05
David Alden, James Tang, davidalden98@yahoo.com
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var x;
function cB(stat,where){
stat2=stat;
if(stat=='key'&&document.forms
[0].insMode.checked==true){
document.forms[0].insMode.checked=false;
stat=false;
}
else if(stat=='key'&&document.forms
[0].insMode.checked==false){
document.forms[0].insMode.checked=true;
stat=true;
}
if (stat==true){
document.getElementById
('status').style.color='red';
document.getElementById
('status').innerHTML='ovr';
}
else{
document.getElementById
('status').style.color='black';
document.getElementById
('status').innerHTML='ins';
}
if(stat2!='key'){
where.focus();
}
}
function checkArrows(x,where){
if(x!=37&&x!=38&&x!=40&&x!=8&&x!=45){
overwrite(where);
}
}
function overwrite(where) {
if(document.forms[0].insMode.checked==true){//comment
this if you want overwrite mode by default
if (document.selection) {
where.focus();
sel = document.selection.createRange();
if(sel.text==""){
sel.text='µµµ';
dummy = where.createTextRange
();
dummy.findText('µµµ');
dummy.select();
pos=where.value.indexOf('µµµ');
begin=pos;
document.selection.clear();
dummy.moveEnd('character',1);
dummy.select();
where.focus();
}
}
else if (where.selectionStart ||
where.selectionStart == '0') {
begin = where.selectionStart;
end = where.selectionEnd;
if(end==begin){
where.selectionEnd=end+1;
where.focus();
}
}
}//comment this if you want overwrite mode by default
}
//-->
</script>
</head>
<body onkeydown="if(event.keyCode==45){x=event.keyCode;cB
('key',document.forms[0].txt);return false}">
<form name=frm>
<textarea name="txt" onkeydown="var
x=event.keyCode;checkArrows(x,this)">abcdefgdefghijklmno</textarea>
<input type="checkbox"
name="insMode" onclick="cB
(this.checked,this.form.txt);"> overwrite mode<br>
<span id="status">ins</span>
<br>
<br>
This textarea will not be affected even if an IE user
pressed the ins key:
<br>
<textarea name="txt2">abcdefgdefghijklmno</textarea>
</form>
</body>
</html>