Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-23-2010, 09:47 AM   PM User | #1
Space_monkey
New to the CF scene

 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Space_monkey is an unknown quantity at this point
A jQuery hotkeys plug in and some AJAX

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.
Code:
<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
Code:
<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
Space_monkey is offline   Reply With Quote
Old 11-23-2010, 03:47 PM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Untested, but something like this should probably work:
Code:
<script>
jQuery(document).bind('keyup', 'ctrl+return', function ()
{
    var content = $('#editable').html();
        $.ajax({
            url: 'saveToDb.php',
            type: 'POST',
            data: {
                content: content
            }
        });
}
);
</script>
Spudhead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:04 PM.


Advertisement
Log in to turn off these ads.