hello everyone, I have found a script where it inserts bbcode into my textarea form, the only thing is wron, it doesnt work in Firefox only IE, it refreshes the page when you click the button.
This is the js script-
and this is what i use to insert a button command into the textarea.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.reply.yourpost.value; caretPos.text = '['+text+']'+caretPos.text+'[/'+text+']'; document.all.FinishedText.innerHTML = replace(document.all.reply.yourpost.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.reply.yourpost.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.reply.yourpost.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.reply.yourpost.value = undoLastText; document.all.FinishedText.innerHTML = replace(document.all.reply.yourpost.value,'\n','<BR>'); } function addText(text){ document.getElementById('yourpost').value += text; } //--> </SCRIPT>
can anyone tell me why it only works in IE and not firefox or opera, also i dont want to use one of those html editor things I like my own simple one, so if you found any tutorials please help.Code:<Button TYPE="image" VALUE="B" onClick="insertAtCaret(this.form.yourpost,\'B\');" ID="BoldButton" NAME="BoldButton" style="BORDER-RIGHT: #ffffff 0px; BORDER-TOP: #ffffff 0px; BORDER-LEFT: #ffffff 0px; BORDER-BOTTOM: #ffffff 0px; BACKGROUND-COLOR: #ffffff;"> <img src="http://www.xudas.com/forum/forum/images/bold.gif"></button>



(:
Reply With Quote

Bookmarks