# Formatting selected text

**URL:** <https://forum.kirupa.com/t/formatting-selected-text/178268>\
**Category:** Uncategorized\
**Created:** [February 8, 2006, 11:54pm UTC](https://forum.kirupa.com/t/formatting-selected-text/178268 "2006-02-08T23:54:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dColumbus](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@dColumbus](https://forum.kirupa.com/u/dColumbus)\
**Post date:** [February 8, 2006, 11:54pm UTC](https://forum.kirupa.com/t/formatting-selected-text/178268/1 "2006-02-08T23:54:24Z")

</div>

How would I be able to do this, but from a button… each time i’ve tried, it seems to deselect the text when i press on the button… thus the changes aren’t made. Should I store the selected in a variable and then when I call the function from the button it pulls in that variable?

What are your thoughts?

```auto
function doFormat() {
 var startIndex:Number = Selection.getBeginIndex();
 var endIndex:Number = Selection.getEndIndex();
 var stringToUppercase:String = output_txt.text.substring(startIndex, endIndex);
 var format2_fmt:TextFormat = new TextFormat();
 format2_fmt.bold = true;
 output_txt.setTextFormat(startIndex, endIndex, format2_fmt);
}

```

[FONT=Courier New]

[/FONT]
