function insertAtCursor(myField, myValue) { //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value += myValue; } } // calling the function //insertAtCursor(document.formName.fieldName, ‘this value’); function setCaretToPos (elm, pos) { setSelectedTextRange(elm, pos, pos); } function getCaretPosition(elm) { if (typeof elm.selectionStart != "undefined") return elm.selectionStart; else if (document.selection) return Math.abs(document.selection.createRange().moveStart("character",-1000000)); } function setSelectedTextRange(elm, selectionStart, selectionEnd) { if (elm.setSelectionRange) { elm.focus(); elm.setSelectionRange(selectionStart, selectionEnd); } else if (elm.createTextRange) { var range = elm.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } }