www.webdeveloper.com
Results 1 to 2 of 2

Thread: Keydown Left and Right arrow for next page Problem

Hybrid View

  1. #1
    Join Date
    Oct 2013
    Posts
    1

    Keydown Left and Right arrow for next page Problem

    I'm using this code for the left arrow (and a similiar code for right arrow), to go to the next page when pressed. The code works fine, without problems. Except I have a comment section which uses a text area. When typing in the textarea I'd like to turn this javascript off so the user can navigate left and right through the text area. Is their anyway to do this? I was thinking if focus on textarea make the key event do nothing. Would anything like that be possible?

    Code:
    <script type="text/javascript">
    			$(document).keydown(function(e){
    				if (e.keyCode == 39) { 
    				   //alert( "left pressed" );
    				   window.location.assign("http://marveldcforum.com/newx.php?x=2");
    				   return false;
    				}
    			});
    </script>
    Thanks in advance

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>123</title>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    </head>
    <body>
    <center>
    <textarea id="comments" rows="5" cols="30"></textarea>
    </center>
    <script type="text/javascript">
    var busy=false;
    $('#comments').focus(function(){busy=true;});
    $('#comments').blur(function(){busy=false;});
    $(document).keydown(function(e){
    if(!busy){
    if(e.keyCode==39){
    alert("right pressed");
    return false;
    }
    }
    });
    </script>
    </script>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles