Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •