0

TEXTAREA can post HTML but we have to write HTML on in it while user doesn't know about html and Textarea does not allow short keys like Ctrl + B for bold.

CONTENTEDITABLE="True" property of Div element. It allows writing HTML Code and Short Keys or any kind of HTML you copy from the other resource.

My is case is that i just want bold, italic, Underline and Enter Key. if i use textarea it does not allow me short keys for edit the html andif i use contenteditable it gives me that features and so many others that i dont allow to user to post.

I am not going for the TinyMC BBCode and so on. for the simple features like bold, italic, underline and enter.

What should i do for that?

zeex
  • 1
  • 5

1 Answers1

0

You need Javascript - Can div with contenteditable=true be passed through form?

Code by smdrager from link above.

<script type="text/javascript">
    function getContent(){
        document.getElementById("my-textarea").value = document.getElementById("my-content").innerHTML;
    }
</script>


<div id="my-content" contenteditable="true"><a href="page.html">Some</a> Text</div>

<form id="form" action="some-page.php" onsubmit="return getContent()">
    <textarea id="my-textarea" style="display:none"></textarea>
    <input type="submit" />
</form>

For allowing only some tags use this: http://phpjs.org/functions/strip_tags/

Community
  • 1
  • 1
Andy
  • 1,035
  • 1
  • 12
  • 28
  • yep i did it, but everything you will put on the div you will get in the textarea. i just want to allow the simple features and nothing more. thanks for reply. – zeex Dec 31 '13 at 11:24
  • This will be helpful: http://phpjs.org/functions/strip_tags/ then set textarea value to `strip_tags(document.getElementById("my-content").innerHTML,'')` //or any tags you want – Andy Dec 31 '13 at 11:28
  • hmm yeah it looks better, i think it is the only solution to strip the tags. thanks. – zeex Dec 31 '13 at 11:31