0

could someone help me on this code? when i click right arrowkey on checkbox2, focus should move to submit button.and when i clic

<html><body> <div> <input type="checkbox" id="mycheckbox" autofocus>1</input> <input type="checkbox" id="mycheckbox"/>2 </div> <div> <input type="button" value="submit"></input> <input type="button" value="reset"></input> </div> <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script> <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(); } else { $(this).next('input').focus(); } } if (keycode ==37) { if($(this).prevAll('input').length === 0) { $('input:enabled:last').focus(); } else $(this).prev('input').focus(); } event.stopPropagation(); }); }); function clickCheckBox(box) { var $box = $(box); $box.prop('checked',!$box.prop('checked')); } </script> </body></html>

18th Mar 2020, 11:39 AM
Guess Me
Guess Me - avatar
1 ответ
+ 3
For id, it shouldn't be the same on two elements so you can <input id="box1" > <input id="box2" > if you want to group the checkbox, use name attribute. <input type="checkbox" name="question1" > <input type="checkbox" name="question2" > Lastly, you don't need to <input>1</input> only <input> 1 <input> 2 if you want new line <p><input>1</p> <p><input>2</p> I don't have a keyboard now so I'll leave the functionality to others. Also, your question is incomplete due to word limit of title. When asking questions in SoloLearn, put your question body in question description, put your code in code playground and link here: with the + button https://www.sololearn.com/post/75089/?ref=app
18th Mar 2020, 3:59 PM
Gordon
Gordon - avatar