Forum Moderators: open
<script type="text/javascript">
function saveCurRng() {
curRng = document.selection.createRange().duplicate();
}
function surround(btag, etag){
if (curRng) {
document.editform.article.focus();
curRng.text= btag + curRng.text + etag;
return false;
}
}
</script>
</head>
<body>
<form name="editform">
<textarea rows=5 cols=40 name="article" onKeyup="saveCurRng()" onMouseup="saveCurRng()"></textarea>
</form>
<a href="#" onclick="return surround('<b>', '</b>');">bold</a><br>
<a href="#" onclick="return surround('<i>', '</i>');">italic</a>
Unfortunately, this only works in IE.
first script:
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
// - frm : form name as object
// - resultfld : result field name as object
// - dowhat : text of html tag as text
// - obj : calling object
function replacesingle(frm,resultfld,dowhat,obj){
tagopen="<"+dowhat+">";
tagclose="</"+dowhat+">";
if(obj.options){
opts=obj.options[obj.selectedIndex].value;
len=opts.length;
split=opts.indexOf(",");
mod=opts.substring(0,split);
modval=opts.substring(split+1,len);
tagopen="<"+dowhat+" "+mod+"=\""+modval+"\">";
tagclose="</"+dowhat+">";
}
var SelectedString = document.selection.createRange().text;
var ReplaceString = tagopen+SelectedString+tagclose;
document.selection.createRange().text = ReplaceString;
}
//-->
</script>
</head>
<body>
<form name="theform" id="theform">
Highlight Text then click a button<br>
<input type=button name=bold value=bold onClick="replacesingle(theform,newsletter,'b',this)">
<input type=button name=italic value=italic onClick="replacesingle(theform,newsletter,'i',this)">
<input type=button name=bullet value=bullet onClick="replacesingle(theform,newsletter,'li',this)">
<select name="color" id="color" onchange="replacesingle(theform,newsletter,'font',this)">
<option selected>Color Chooser</option>
<option value="color,FF0000" style="background-color:#FF0000;"></option>
<option value="color,00FF00" style="background-color:#00FF00;"></option>
<option value="color,0000FF" style="background-color:#0000FF;"></option>
</select><br>
<textarea name="newsletter" id="newsletter">this is a text</textarea>
</body>
</html>
second:
<td colspan=2 align="center">
<div id="cdiv" style='position:relative; left:0px; top:0px; height:314px; width:603px;border:solid 1px #9C9C9C;'>
<textarea name="body" wrap="soft" style='visibility:visible; z-index:100; position:absolute; left:0px; top:0px; height=100%; width=100%'>Testo Testo Testo </textarea>
<IFRAME SRC="/cgi-bin/dasp/EN/rte.asp" id='richedit' style='visibility: hidden; position: absolute; left: 0px; top: 0px; height=100%; width=100%'></IFRAME>
</div>
</td>