If a user clicks the button "Bold" or "BR with the code above,"Code:<script type='text/javascript'> <!-- function ubbc(open, end){ var tArea = document.myform.box1; var isIE = (document.all)? true : false; var open = (open)? open : ""; var end = (end)? end : ""; if(isIE){ tArea.focus(); var curSelect = document.selection.createRange(); if(arguments[2]){ curSelect.text = open + arguments[2] + "]" + curSelect.text + end; } else { curSelect.text = open + curSelect.text + end; } } else if(!isIE && typeof tArea.selectionStart != "undefined"){ var selStart = tArea.value.substr(0, tArea.selectionStart); var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length); var curSelection = tArea.value.replace(selStart, '').replace(selEnd, ''); if(arguments[2]){ tArea.value = selStart + open + arguments[2] + "]" + curSelection + end + selEnd; } else { tArea.value = selStart + open + curSelection + end + selEnd; } } else { tArea.value += (arguments[2])? open + arguments[2] + "]" + end : open + end; } } //--> </script> <form name="myform" action='action.cfm'> <textarea name='box1' cols='88' rows='3'></textarea> <input type='button' value='Bold' onclick="ubbc('<b>', '</b>')" /> <input type='button' value='BR' onclick="ubbc('<br>')" /> </form>
"<b>,</b>" or "<br>" tag will be generated in the textArea.
Let's suppose I have many textAreas in the form.
I like to make "Bold" and "BR" buttons at each textArea.
The following is one of my trial codes, and it doesn't work correctly.
How can I make the trial code work?Code:trial code <script type='text/javascript'> <!-- function ubbc(open, end){ var tArea = document.myform.box1; var isIE = (document.all)? true : false; var open = (open)? open : ""; var end = (end)? end : ""; if(isIE){ tArea.focus(); var curSelect = document.selection.createRange(); if(arguments[2]){ curSelect.text = open + arguments[2] + "]" + curSelect.text + end; } else { curSelect.text = open + curSelect.text + end; } } else if(!isIE && typeof tArea.selectionStart != "undefined"){ var selStart = tArea.value.substr(0, tArea.selectionStart); var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length); var curSelection = tArea.value.replace(selStart, '').replace(selEnd, ''); if(arguments[2]){ tArea.value = selStart + open + arguments[2] + "]" + curSelection + end + selEnd; } else { tArea.value = selStart + open + curSelection + end + selEnd; } } else { tArea.value += (arguments[2])? open + arguments[2] + "]" + end : open + end; } } //--> </script> <form name="myform" action='action.cfm'> <textarea name='box1' cols='88' rows='3'></textarea> <input type='button' value='Bold' onclick="ubbc('<b>', '</b>')" /> <input type='button' value='BR' onclick="ubbc('<br>')" /> <textarea name='box2' cols='88' rows='3'></textarea> <input type='button' value='Bold' onclick="ubbc('<b>', '</b>')" /> <input type='button' value='BR' onclick="ubbc('<br>')" /> <textarea name='box3' cols='88' rows='3'></textarea> <input type='button' value='Bold' onclick="ubbc('<b>', '</b>')" /> <input type='button' value='BR' onclick="ubbc('<br>')" /> </form>




Bookmarks