javascript - Enter to Tab script does not pass over a checkbox? -
i trying convert enter tab, , works perfect form fields, not checkbox on page. have ideas why not?
enter tab code :
<script type="text/javascript"> function tabe(obj, e) { var e = (typeof event != 'undefined') ? window.event : e; // ie : moz var self = $(obj), form = self.parents('form:eq(0)'), focusable, next; if (e.keycode == 13) { focusable = form.find('input,a,select,button,textarea').filter(':visible'); next = focusable.eq(focusable.index(obj) + 1); if (!next.length) { next = focusable.first(); } next.focus(); return false; } } </script>
the evil checkbox :
<input class="case" type="checkbox" onkeyup="return tabe(this,event);"/>
edit: (html code) :
<td> <input class="case" type="checkbox" onkeypress="return tabe(this,event);"/> </td>
jquery :
html += '<td><input class="case" id="caseno_'+i+'" type="checkbox"/></td>';
it works me. updated show continues work if checkboxes created dynamically.
function tabe(obj, e) { var e = (typeof event != 'undefined') ? window.event : e; // ie : moz var self = $(obj), form = self.parents('form:eq(0)'), focusable, next; if (e.keycode == 13) { focusable = form.find('input,a,select,button,textarea').filter(':visible'); next = focusable.eq(focusable.index(obj) + 1); if (!next.length) { next = focusable.first(); } next.focus(); return false; } } var lid = 0; $(function () { $('#addnewcheck').on('click', function(e) { lid +=1; $('<input id="' + lid + '" class="case" type="checkbox" onkeypress="return tabe(this,event);"/>').insertafter(':checkbox:last'); }); });
<script src="http://code.jquery.com/jquery-1.11.3.js"></script> <form action="action_page.php"> first name:<br> <input type="text" name="firstname" value="mickey" onkeypress="return tabe(this,event);"><br> last name:<br> <input type="text" name="lastname" value="mouse" onkeypress="return tabe(this,event);"><br><br> case:<br> <input class="case" type="checkbox" onkeypress="return tabe(this,event);"/> <br> <input type="submit" value="submit" onkeypress="return tabe(this,event);"> </form> <br> <button id="addnewcheck">add new checkbox </button>
Comments
Post a Comment