Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi.

I'm using javascript and jQuery.
I have a textarea and 2 buttons to bold/underline the value of textarea.
My control: when user select text in textarea and click bold button, the text will be bold automatically.

I've done that.

Now, I want that: After user selects text and clicks bold button to bold text, it will automatic focus textarea and re-select the text.

JavaScript
// code for bold button
function Bold()
{
// code to bold the selected text here. I'm done.

// use jQuery to focus textarea with id ="myarea"
$("#myarea").focus();

// now, how to let it automatic select the selected text?
}


The main problem: if user wants to bold and underline the selected text, it needs to be selected once.

My map: Type text to textarea (handle) => select text (handle) => click bold button to bold the selected text (handle) => bold text (code) => auto focus textarea (code) => auto re-select the selected text (code) => click underline button (handle).

So, my main question: How to use javascript/jQuery to select the custom text in textarea (not all text: this.select())?

Sorry if this is not a clearly question.

Thank you!
Posted
Comments
Sharjeel Faiq 18-Apr-22 18:31pm    
What basically is your function to bold the eselected text?

1 solution

 
Share this answer
 
Comments
user8x86 7-May-15 14:39pm    
Many thanks!!!
Sergey Alexandrovich Kryukov 7-May-15 17:50pm    
Sure. Will you accept the answer formally?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900