Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea contenteditable

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.

like image 983
Antony Carthy Avatar asked Oct 14 '09 14:10

Antony Carthy


People also ask

What does Contenteditable mean?

Definition and Usage The contenteditable attribute specifies whether the content of an element is editable or not. Note: When the contenteditable attribute is not set on an element, the element will inherit it from its parent.

What is Contenteditable attribute used for?

The contenteditable global attribute is an enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing.

What is a Contenteditable div?

contenteditable is an HTML attribute that you can add to any HTML element. If its value is true or an empty string, that means that the user can edit it by clicking the element. For example: <div contenteditable="true"> Change me! </ div>

How do you use Contenteditable in HTML?

To edit the content in HTML, we will use contenteditable attribute. The contenteditable is used to specify whether the element's content is editable by the user or not. This attribute has two values. true: If the value of the contenteditable attribute is set to true then the element is editable.


2 Answers

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.

like image 102
Marius Avatar answered Nov 02 '22 11:11

Marius


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>
like image 41
Ben Shelock Avatar answered Nov 02 '22 10:11

Ben Shelock