How can I get the value of the contenteditable after I type on it?
Is there a way of getting the value of it after I click on the div and edit the text and send it to php?..
BTW i am using jquery and php for this. Here is my Code:
<div class="profilestatus"> <a contenteditable>type text here</a></div>
var phrase = '<div class="profilestatus"> <a contenteditable>type text here</a></div>';
var myRegexp = YOUR MATCH PATTERN;
var match = myRegexp.exec(phrase);
alert(match[1]);
Use <input>
instead. You can use CSS to style it to look like the <a>
if needed. You can get the current value of the input with $('input').val();
.
Demo: http://jsfiddle.net/9R5VE/
HTML:
<input value="editable"></input>
jQuery:
$("input").focusout(function(){
alert($(this).val());
});
Maybe :
$('#yourForm').submit(function() {
$('#hiddenInput').attr(
'value',
$('.profilestatus').first().children(0).html()
);
});
?
You can also style a <textarea>
using CSS. This would avoid you to have an hidden input.
I was trying for ages to get the content to highlight automatically, but could not do it with neither JS nor jQuery :(
Anyway, this is what I have:
Working example: here
<script>
function formSubmit(content)
{
document.eForm.link.value = content;
document.eForm.submit();
}
</script>
<?php
$link = isset($_POST['link']) ? $_POST['link'] : NULL;
($link !== NULL) ?
((stripos($link, 'http://') === FALSE) ?
header('Location: http://'.strip_tags($link)) :
header('Location: '.strip_tags($link))) : true;
?>
<form name="eForm" method="Post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input id="try" type="hidden" name="link" />
<div id="eDiv" class="profilestatus" contenteditable>
<a id="eLink" onclick="formSubmit(document.getElementById('eLink').innerHTML)">highlight, type, click!</a>
</div>
</form>