vzhen
vzhen

Reputation: 11157

jQuery change div to HTML5 contenteditable and pass to php

Current I have the following div

 <div class="tag-header">
    <?php echo $row->name; ?>
 </div>

And I add the contenteditable to the div with .attr

$('.tag-header').attr("contenteditable", "true");

But my problem is how to pass the value to php and post to database? *NOTE: I'm not ready to use ajax just normal php submit.

Upvotes: 1

Views: 1918

Answers (1)

Wolf
Wolf

Reputation: 2150

Added a demo here

Update html to

<form>
<div class="tag-header">
    <?php echo $row->name; ?>
 </div>
<input type="hidden" id="tagval" />
</form>

Then use the focusout event to bind

$(".tag-header").focusout(function() {
   $("#tagval").val($(".tag-header").text());
});

Submit the form to get the value in PHP.

Upvotes: 1

Related Questions