Code:
<SCRIPT LANGUAGE=javascript>
<!--
var undoLastText = "Reset (no previous record)"
function storeCaret(TextAreaContent)
{
if (TextAreaContent.createTextRange) TextAreaContent.caretPos = document.selection.createRange().duplicate();
}
function insertAtCaret(TextAreaContent, text)
{
if (TextAreaContent.createTextRange && TextAreaContent.caretPos)
{
var caretPos = TextAreaContent.caretPos;
undoLastText = document.all.frmAdd1.Copy.value;
caretPos.text = '['+text+']'+caretPos.text+'[/'+text+']';
document.all.FinishedText.innerHTML = replace(document.all.frmAdd1.Copy.value,'\n','<BR>');
}
else
alert("Please select some text for formatting");
}
function insertLinkAtCaret(TextAreaContent, text)
{
if (TextAreaContent.createTextRange && TextAreaContent.caretPos)
{
var caretPos = TextAreaContent.caretPos;
undoLastText = document.all.frmAdd1.Copy.value;
cheese = prompt('Please enter the full URL for this link','http://');
caretPos.text = '['+text+'="'+cheese+'"]'+caretPos.text+'[/'+text+']';
document.all.FinishedText.innerHTML = replace(document.all.frmAdd1.Copy.value,'\n','<BR>');
}
else
alert("Please select the word or phrase which you wish to hyperlink");
}
function replace(string,text,by) {
// Replaces text with by in string
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}
function undoLast()
{
document.all.frmAdd1.Copy.value = undoLastText;
document.all.FinishedText.innerHTML = replace(document.all.frmAdd1.Copy.value,'\n','<BR>');
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM ID="frmAdd1" NAME="frmAdd1">
TEXTAREA:<BR>
<TEXTAREA STYLE="padding: 5px; background: palegreen; border: 1px solid black; font-family: verdana, arial, sans-serif; color: black; font-size: 10pt; width: 360;" COLS="50" ROWS="7" NAME="Copy" ID="Copy" onSelect="storeCaret(this);" onClick="storeCaret(this);" onKeyUp="storeCaret(this);">I wandered lonely as a cloud
That floats on high o'er vales and hills,
When all at once I saw a crowd,
A host, of golden daffodils,
Beside the lake, beneath the trees,
Fluttering and dancing in the breeze.</TEXTAREA><P>
<SPAN STYLE="font-family: verdana, arial, sans-serif; font-size: 8pt;">Select some text above, then click a format button - a bit like in Word</SPAN><P>
<INPUT TYPE="BUTTON" STYLE="font-family: verdana, arial, sans-serif; font-weight: bold; width: 30px;" VALUE="B" onClick="insertAtCaret(this.form.Copy,'B');" ID="BoldButton" NAME="BoldButton">
<INPUT TYPE="BUTTON" STYLE="font-family: verdana, arial, sans-serif; font-style: italic; font-weight: bolder; width: 30px;" VALUE="I" onClick="insertAtCaret(this.form.Copy,'I');" ID="ItalicButton" NAME="ItalicButton">
<INPUT TYPE="BUTTON" STYLE="font-family: verdana, arial, sans-serif; text-decoration: underline; font-weight: bolder; width: 30px;" VALUE="U" onClick="insertAtCaret(this.form.Copy,'U');" ID="ItalicButton" NAME="ItalicButton">
<INPUT TYPE="BUTTON" STYLE="font-family: verdana, arial, sans-serif; text-decoration: underline; font-weight: bolder; width: 80px; color: blue; cursor: hand;" VALUE="Add Link" onClick="insertLinkAtCaret(this.form.Copy,'url');" ID="LinkButton" NAME="LinkButton">
<INPUT TYPE="BUTTON" STYLE="font-family: verdana, arial, sans-serif; font-weight: bolder; width: 80px; color: green; cursor: hand;" VALUE="Undo Last" onClick="undoLast();" ID="UndoButton" NAME="UndoButton"><P>
<BR><BR>
<img src="http://www.xudas.com/images/xudasaffy.gif" border="0" onClick="undoLast();" ID="UndoButton" NAME="UndoButton"><P>
</FORM>
</BODY>
</HTML>
I was playing with this.. and it works better then yours .. Thanksyou though..
Bookmarks