Hallo, Ralph,
ist es moeglich, per JavaScript etwas in Formulare einzusetzen und zwar an der aktuellen Cursorposition?
Diese aufwändige Lösung wurde mal irgendwo gepostet ...
Grüße, Sebastian
--------------- schnipp ---------------
<!--
Here's some html editing code that works with IE.
It won't work on netscape and doesn't work on mac...
But if you have a limited environment.
-->
<script language=javascript>
<!--
function markSelection(txtObj)
{
if(txtObj.createTextRange) {
txtObj.caretPos = document.selection.createRange().duplicate();
isSelected = true;
}
}
function insertTag(txtName,tag,enclose)
{
var closeTag = tag;
if(enclose) {
var attribSplit = tag.indexOf(' ');
if(tag.indexOf(' ') > -1)
closeTag = tag.substring(0, attribSplit);
}
if(isSelected){
var txtObj = eval("document.forms[0]." + txtName);
if(txtObj.createTextRange && txtObj.caretPos) {
var caretPos = txtObj.caretPos;
caretPos.text =((enclose) ? "<"+tag+">"+caretPos.text+"</"+closeTag+">" : "<"+tag+">"+caretPos.text);
markSelection(txtObj);
if(txtObj.caretPos.text=='') {
isSelected=false;
txtObj.focus();
}
}
} else {
// placeholder for loss of focus handler
}
}
//-->
</script>
<form>
<textarea name="tsttxt" ONSELECT="markSelection(this);" ONCLICK="markSelection(this);" ONKEYUP="markSelection(this);"></textarea>
<input type="button" value="BOLD" onClick="insertTag('tsttxt', 'b', true)">
<input type="button" value="PARAGRAPH" onClick="insertTag('tsttxt', 'p', false)">
</form>
--------------- schnipp ---------------