Using HTML5, how do I use contenteditable fields in a form submission?

You have to use javascript one way or the other, it won’t work as a “standard” form element as it would with a textarea or the like. If you like, you could make a hidden textarea within your form, and in the form’s onsubmit function copy the innerHTML of the contenteditable to the textarea’s value. Alternatively you could use ajax/xmlHttpRqeuest to submit the stuff a bit more manually.

function copyContent () {
    document.getElementById("hiddenTextarea").value =  
        document.getElementById("myContentEditable").innerHTML;
    return true;
}


<form action='whatever' onsubmit="return copyContent()">...

Leave a Comment