Nieuw lid |
|
function addText(foname, elname, wrap1, wrap2) {
if (document.selection) { // for IE
var str = document.selection.createRange().text;
document.forms[foname].elements[elname].focus();
var sel = document.selection.createRange();
sel.text = wrap1 + str + wrap2;
return;
} else if ((typeof document.forms[foname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
var txtarea = document.forms[foname].elements[elname];
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var oldScrollTop = txtarea.scrollTop;
//if (selEnd == 1 || selEnd == 2)
//selEnd = selLength;
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
txtarea.selectionStart = s1.length;
txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
txtarea.scrollTop = oldScrollTop;
txtarea.focus();
return;
} else {
insertText(foname, elname, wrap1 + wrap2);
}
}
function insertText(foname, elname, what) {
if (document.forms[foname].elements[elname].createTextRange) {
document.forms[foname].elements[elname].focus();
document.selection.createRange().duplicate().text = what;
} else if ((typeof document.forms[foname].elements[elname].selectionStart) != 'undefined') { // for Mozilla
var tarea = document.forms[foname].elements[elname];
var selEnd = tarea.selectionEnd;
var txtLen = tarea.value.length;
var txtbefore = tarea.value.substring(0,selEnd);
var txtafter = tarea.value.substring(selEnd, txtLen);
var oldScrollTop = tarea.scrollTop;
tarea.value = txtbefore + what + txtafter;
tarea.selectionStart = txtbefore.length + what.length;
tarea.selectionEnd = txtbefore.length + what.length;
tarea.scrollTop = oldScrollTop;
tarea.focus();
} else {
document.forms[foname].elements[elname].value += what;
document.forms[foname].elements[elname].focus();
}
}
function addText(foname, elname, wrap1, wrap2) { if (document.selection) { // for IE var str = document.selection.createRange().text; document.forms[foname].elements[elname].focus(); var sel = document.selection.createRange(); sel.text = wrap1 + str + wrap2; return; } else if ((typeof document.forms[foname].elements[elname].selectionStart) != 'undefined') { // for Mozilla var txtarea = document.forms[foname].elements[elname]; var selLength = txtarea.textLength; var selStart = txtarea.selectionStart; var selEnd = txtarea.selectionEnd; var oldScrollTop = txtarea.scrollTop; //if (selEnd == 1 || selEnd == 2) //selEnd = selLength; var s1 = (txtarea.value).substring(0,selStart); var s2 = (txtarea.value).substring(selStart, selEnd) var s3 = (txtarea.value).substring(selEnd, selLength); txtarea.value = s1 + wrap1 + s2 + wrap2 + s3; txtarea.selectionStart = s1.length; txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length; txtarea.scrollTop = oldScrollTop; txtarea.focus(); return; } else { insertText(foname, elname, wrap1 + wrap2); } } function insertText(foname, elname, what) { if (document.forms[foname].elements[elname].createTextRange) { document.forms[foname].elements[elname].focus(); document.selection.createRange().duplicate().text = what; } else if ((typeof document.forms[foname].elements[elname].selectionStart) != 'undefined') { // for Mozilla var tarea = document.forms[foname].elements[elname]; var selEnd = tarea.selectionEnd; var txtLen = tarea.value.length; var txtbefore = tarea.value.substring(0,selEnd); var txtafter = tarea.value.substring(selEnd, txtLen); var oldScrollTop = tarea.scrollTop; tarea.value = txtbefore + what + txtafter; tarea.selectionStart = txtbefore.length + what.length; tarea.selectionEnd = txtbefore.length + what.length; tarea.scrollTop = oldScrollTop; tarea.focus(); } else { document.forms[foname].elements[elname].value += what; document.forms[foname].elements[elname].focus(); } }
aan te roepen door
addText('form','field','[b]','[/b]')
addText('form','field','[b]','[/b]')
form en field spreekt voor zick lijkt mij |