1

I have a code which bold the complete text present in textarea but i want to Bold only selected text to be bold present in text area. Note that i don't want the text to be in Div tags. I want to do the same with text area only. here is my code:

    <form action="index.html" name="theform">
    <input type="button" onclick="setClass('');" value="Normal" />
    <input type="button" onclick="setClass('italics');" value="Italics" />
    <input type="button" onclick="setClass('bolded');" value="Bold" />
    <textarea id="txt">This is some text in our textarea</textarea>

and here is my javascript code

<script type="text/javaScript">
    function setClass(class_name) {
        document.getElementById('txt').className = class_name;
    }
</script>

above code bold the complete text but not the selected text

Yash Katiyar
  • 31
  • 1
  • 1
  • 8
  • 1
    because bold text need strong or b tag, you can not insert html tag in the textarea field. you just can set style bold just for all textarea content and not for selected text – Mohammad Jan 09 '18 at 05:46
  • "Note that i don't want the text to be in Div tags...". But you can't do without divs. Refer to https://stackoverflow.com/questions/4705848/rendering-html-inside-textarea – vibhor1997a Jan 09 '18 at 05:48
  • Use advanced `textarea` like ckeditor or tinymce, or use editable div. you can't do this in `textarea` – Pedram Jan 09 '18 at 06:14

0 Answers0