Expand my Community achievements bar.

Changing style of text selection in text box

Avatar

Former Community Member
Hi,



We are trying to assign code to buttons mimic the same functionality the user get when (s)he select a text in a text box and try to change the font or style (e.g., press Ctrl+B to get the highlighted text bolded, or Ctrl+I to get it italic, or Ctrl+U to get it underlined) via JavaScript.



What are the objects, methods, and properties that we should use in our code?



Is the selected text accessible?



If my text filed called txtRichText can I do something like this:

txtRichText.Selection.Style = Bold?



BR,



Yasser
2 Replies

Avatar

Former Community Member
If I understand correctly, you have a form in which you have a text field whose data type you've set to be rich text (XHTML) and you're wanting to put buttons on the form which let the user format the current selection in that text field in order to make the selection bold, italic and/or underlined.



Unfortunately, I don't believe this is possible. JavaScript on its own doesn't provide an object which represents the current selection. If such an object exists, it's because it's implemented by the target client (like in HTML -- the client being the browser in this case -- where I believe you have access to a
document.selection object which you can use to modify the selected text). Since neither XFA nor Acrobat expose an object which gives you access to the selection, you can't do anything with it.



Fortunately, Acrobat has a built-in text formatting toolbar which will do essentially what you're trying to achieve with your request. You can access it by selecting text in a rich text field (set the text field's Field Format to
Rich Text and its Data Format to
XHTML using the Object palette) and then pressing "Ctrl + E". This will open the text formatting toolbar with buttons for setting bold, italic, underline, strike-through, super script, font type, size, etc., and even paragraph alignment settings!



Stefan

Adobe Systems

Avatar

Former Community Member
Hi Stefan,



Many thanks for this information. I do appreciate it.



I can understand that this not possible (easily). However, it seems it'll be nice to have these properties exposed in an object called selection, for example. Maybe this will be one of the enhancement requests.



BR,



Yasser

SOMAC-IT (Adobe Enterprise Solutions Master Distributor, Middle East)