views:

552

answers:

4

I am trying to make a textarea content editable and I am failing. I am using this code:

<textarea id='' class='' name='notes' rows='12' cols='67' contenteditable='true' ></textarea>

I am expecting a result like http://html5demos.com/contenteditable

Does anyone have an idea why it's not working?

Edit:

I am doing this because I am trying to do a oneliner to add a control to a form in which (HTML) formatted content can be pasted and retain its formatting. I am trying to do this without fuss and without javascript code. It appears this is not possible. I will close this question in a day if no further input to the contrary is added.

A: 

They are not using a textarea, textareas are already editable. This is what they are using

<section contenteditable="true" id="editable">
    <h2>Go ahead, edit away!</h2>
    <p>Here's a typical paragraph element</p>
    <ol>
      <li>and now a list</li>
      <li>with only</li>
      <li>three items</li>
    </ol>
  </section>
Ben Shelock
I was hoping for a WYSIWYG where one can paste bold text etc. The reason for this is that I need to post this in a form submit after it's been edited.
Antony Carthy
+1  A: 

Have you set the right doctype at the top of your page? For HTML5 you need the following doctype:

<!DOCTYPE html>

Also, why a textarea? textareas are already editable.

Marius
As on Ben's post, I was hoping for a WYSIWYG where one can paste bold text etc and retain formatting . The reason for this is that I need to post this in a form submit after it's been edited.
Antony Carthy
The form will not submit the formatting. Instead put it in a div and use onSumbit to read the innerHTML of the div.
Marius
Thanks Marius. I was hoping to KISS, but there we go.
Antony Carthy
A: 

Given your comment responses, I would recommend any of the excellent WYSIWYG editors out there. No need to re-invent the wheel, and I don't think contenteditable wouldn't have met your needs anyway.

My personal favorite is CKEditor, but there are many, many others. TinyMCE is also very popular.

anschauung
I was hoping for a oneliner to solve my problems (just needed a simple text area that could hold formatted text) but this is apparently not on the cards. Thanks for the suggestion though.
Antony Carthy
+1  A: 

I don't mean to repeat anything, but I've put together a demo that shows what is happening.

http://gist.github.com/210327

Just run that, edit what you wish and click the 'Output Formatted Content' statement to receive an alert message with an output of the actual html-formatted content in the contenteditable element. As for adding formatting, etc, you'll need to make buttons that call a text-modifying function on whatever is highlighted. Yeah, that part will be fun.

Nonetheless, I hope this helps.

slant
+1 for effort, but it's not quite what I needed... because I think what I needed is not possible.
Antony Carthy