Hallo zusammen , ich habe hier ein kleines Script so das ich BBCodes in eine Textarea bekomme
nun möchte ich aber ein Smilie einfügen , versuche wie :
<img src='../bilder/smilies/confused.gif' onclick="cur_ins(this.form.text, ':confuse:');" alt='verwirrt'>
schlugen fehl . Kann mir da jemand ein Tip geben ?
mfg Launebaer
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript" type="text/javascript">
function cur_ins(field, startTag, endTag, offset) {
field.focus();
if (document.getSelection) { //FF, NS
selStart = field.selectionStart;
selEnd = field.selectionEnd;
text = field.value.substring(selStart, selEnd);
field.value = field.value.substring(0, selStart) + startTag + text + endTag + field.value.substring(selEnd);
if (text.length > 0) {
if (offset != 0) {
field.selectionStart = selStart + startTag.length + text.length - offset;
} else {
field.selectionStart = selStart + startTag.length + text.length + endTag.length;
}
} else {
field.selectionStart = selStart + startTag.length;
}
field.selectionEnd = field.selectionStart;
} else
if (document.selection) { //IE
marker = document.selection.createRange();
text = marker.text;
marker.text = startTag+text+endTag;
marker = document.selection.createRange();
if (text.length > 0) {
if (offset != 0) {
marker.move('character', startTag.length + text.length - offset);
} else {
marker.move('character', startTag.length + text.length + endTag.length + offset);
}
} else {
marker.move('character', -(endTag.length));
}
marker.select();
}
}
</script>
</head>
<body>
<form action="" method="post">
<textarea id="text" name="text" cols="48" rows="10"></textarea>
<input type="button" value="fett" onclick="cur_ins(this.form.text, '[b]', '[/b]');" name="fett">
<input type="button" value="kursiv" onclick="cur_ins(this.form.text, '[i]', '[/i]');" name="kursiv">
<input type="button" value="unterstrichen" onclick="cur_ins(this.form.text, '[u]', '[/u]');" name="unterstrichen">
<input type="button" value="zentriert"
onclick="cur_ins(this.form.text, '[center]', '[/center]');" name="zentiert">
</form>
</body>
</html>
<img src='../bilder/smilies/confused.gif' onclick="cur_ins(this.form.text, ':confuse:');" alt='verwirrt'>
schlugen fehl . Kann mir da jemand ein Tip geben ?
mfg Launebaer
Moderator
Kommentar