Created
November 16, 2011 15:45
-
-
Save fightbulc/1370413 to your computer and use it in GitHub Desktop.
Make contentEditable saveable (quick&dirty)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>contentEditable</title> | |
<style type="text/css"> | |
div.wrapper | |
{ | |
width:300px; | |
border:1px solid #ccc; | |
} | |
div.field | |
{ | |
float:left; | |
background:#9cf; | |
padding:10px; | |
margin:0 10px 10px 0; | |
} | |
textarea | |
{ | |
display:none; | |
} | |
</style> | |
<script type="text/javascript"> | |
function setContent() { | |
fields = document.getElementsByClassName('field'); | |
for(i=0;i<fields.length;i++) { | |
console.log(fields[i].innerText); | |
fields[i].getElementsByTagName('textarea')[0].value = fields[i].innerText; | |
} | |
return true; | |
} | |
</script> | |
</head> | |
<body> | |
<?php | |
if( ! empty($_POST)) { | |
echo '<pre>'; | |
print_r($_POST); | |
echo '</pre>'; | |
} | |
?> | |
<form action="" method="post" onSubmit="return setContent()"> | |
<div class="wrapper"> | |
<div class="field" contentEditable>Enter your name<textarea name="name"></textarea></div> | |
<div class="field" contentEditable>...and city<textarea name="city"></textarea></div> | |
</div> | |
<input type="submit" value="Send"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment