Skip to content

Instantly share code, notes, and snippets.

@howtomakeaturn
Last active February 2, 2016 10:49
Show Gist options
  • Save howtomakeaturn/951134646fbb10a37ca9 to your computer and use it in GitHub Desktop.
Save howtomakeaturn/951134646fbb10a37ca9 to your computer and use it in GitHub Desktop.
Simple editable div elements. Send ajax when users press enter.
<div contenteditable='true' data-bill-id='xxx' class='notes'></div>
$('.notes').blur(function(e){
    $.ajax({
        url: "/bill/notes",
        method: 'post',
        data: {id: $(e.target).data('bill-id'), notes: $(e.target).text()},
        error: function(res){
            alert('error. please refresh the page and try again.');
        }
    });
});

$('.notes').keypress(function(e){
    if (e.keyCode == 13) {
        $(e.target).blur();
        return false;
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment