I'm trying to set "Ctrl+Enter" to execute function update
:
document.onkeydown = function(e, id){
var keyCode = (window.event) ? e.which : e.keyCode;
if (keyCode == 13 && e.ctrlKey) {
update(id);
}
}
function update(id) {
var title = $("#title"+id).val();
var content = $("#content"+id).val();
$.ajax({
type: "POST",
url: url,
data: {
aid: id,
title: title,
content: content,
},
beforeSend : function(){
alert(content);
},
success: function(data){
$("#view"+id).html(data);
},
});
}
HTML part:
<input type="text" id="title<?php echo $id ?>" >
<textarea id="content<?php echo $id ?>" ></textarea>
It works with click event, but keypress. I tested with the above beforeSend and it returned undefined
. What makes variable content
become undefined
? How could I fix it?