bertino12
asked on
How to make a substring in RichTextBox to bold
I have a richtextbox that contains the string "I want to buy a new computer as soon as possible." and want to have a button to click that makes "as soon as" Bold. How can I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
richtextbox1.select allows you select from some index to some length of text.
After selecting, just make the selection bold as shown by jaime.
After selecting, just make the selection bold as shown by jaime.
Indeed I showed how to use the Select method too.
Looks like Jaime is the winner here :)
* Replace selected elments with the element wrapped in a <tag></tag>
* This function is supposed to be cross-platform
* This function copied from http://codingforums.com/showthread.php?t=134113
*
* @return void
*/
function formatText(el,tag) {
var selectedText=document.sele
var newText='<'+tag+'>'+select
// Do IE compatible replacements
if(document.selection){
document.selection.createR
}
// Do mozilla compatible replacements
else{
el.value=el.value.substrin
}
}
Then call this like so input type="button" onclick="formatText('eleme