...

View Full Version : A jQuery hotkeys plug in and some AJAX



Space_monkey
11-23-2010, 09:47 AM
I wrote a script which when a button is pushed gets the contents of a div and sends it to a php script which then sends it to my database. This all worked fine. the script I was using was this.

<script>
$(document).ready(function() {
$('#save_editable').click(function() {
var content = $('#editable').html();
$.ajax({
url: 'saveToDb.php',
type: 'POST',
data: {
content: content
}
});
});
});
</script>

<div id="editable" contentEditable="true">Lorem ipsum dolor ....</div>
<button id="save_editable">Save</a>

I then thought great thats working now ill trigger the javascript by a key combination (ctrl+enter). So after some hunting I found a jQuery Plugin that looked pretty good. (http://plugins.jquery.com/project/hotkeys)

I set up this code to test it out


<script>
jQuery(document).bind('keyup', 'ctrl+return', function ()
{
alert("Hello!");
}
);
</script>


That worked also worked great so I tried to put the two together in every combination I could think of and I cant get it to work at all. Are these two script not compatible or something?
I put various alert boxes throughout the script as a way debugging, to check how far it gets but I didn't get any alert boxes. Even if I placed them on the very first like of code, which is just odd.

i havent really done much Javascript and obviously this is a bit over my head and more complex than just cutting and pasting together. The jQuery plug in doesn't really have any documentation or examples so any advice would be great!

Thanks! hope it wasnt too long

Spudhead
11-23-2010, 03:47 PM
Untested, but something like this should probably work:


<script>
jQuery(document).bind('keyup', 'ctrl+return', function ()
{
var content = $('#editable').html();
$.ajax({
url: 'saveToDb.php',
type: 'POST',
data: {
content: content
}
});
}
);
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum