-2

Simply tying to bold selected text within the text area

Here my code :

<script type="text/javascript">
function Bold() {
    document.getElementById('firstTextarea').value = 'bold';
</script>

HTML:

<textarea id="firstTextarea" rows="12" cols="40"></textarea>
<button onclick="Bold();">Bold</button>
coder
  • 13,002
  • 31
  • 112
  • 214
devanteaddai
  • 1
  • 1
  • 1
  • You're setting the wrong attribute of the textarea element. See udidu's answer. – Nick Pickering Feb 24 '13 at 13:46
  • You might want to look at this post here: http://stackoverflow.com/questions/275761/how-to-get-selected-text-from-textbox-control-with-javascript – jonasnas Feb 24 '13 at 13:49
  • 1
    This is not possible in a standard textarea elemento. You will have to use a div with editable html or an WYSIWYG editor like ckeditor, cleditor or tiny MCE. – Ricardo Souza Feb 24 '13 at 13:50

1 Answers1

1

You are setting the value attribute of that Textarea field. What you want to set is the font-weight attribute which is done like this:

document.getElementById('firstTextarea').style.fontWeight = 'bold';

Nick Pickering
  • 3,095
  • 3
  • 29
  • 50
udidu
  • 8,269
  • 6
  • 48
  • 68