Jump to content

can someone help me on solving this? the jquery shoculd focus on all div elements..not only on a particular div


ITSMESAM

Recommended Posts

i want my code to be work as when i press arrowkey at checkbox 4, it should focus the submit button element in the next div. but now it is focusing the first checkbox.How to modify it?

 

 

 

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <script src="https://code.jquery.com/jquery-3.1.1.js"></script>
    </head>
    <body>
        <div>
<input type="checkbox"  autofocus/>1
<input type="checkbox" />2
<input type="checkbox" />3
<input type="checkbox" />4
<br/>
<input type="button" value="mycheckbox">
<input type="button" value="mycheckbox">

</div>
        <script>
 $(document).ready(function () {
    $('input').keydown(function (event) {
        var keycode = (event.keyCode ? event.keyCode : event.which);
        if (keycode == 13) {

            clickCheckBox(this);
}
        if (keycode == 39) {
            if($(this).nextAll('input').length === 0) {
              $('input:enabled:first').focus();// first textbox
         }
         else
         {
              $(this).nextAll('input:first').focus();
         }
        }
if (keycode ==37) {
            if($(this).prevAll('input').length === 0) {
           
              $('input:enabled:last').focus();
         }
else
$(this).prevAll('input:first').focus();
        }


       
        event.stopPropagation();
    });
});

function clickCheckBox(box) {
    var $box = $(box);
    $box.prop('checked',!$box.prop('checked'));
}
 
       
   

</script>
    </body>
</html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...