HTML piece
<td><input type="text" name="date1" id="date1" value="<?php echo $_POST['date1']?>" size="1"></td> <td><input type="text" name="amount1" id="amount1" size="5"></td>
This is javascript
<script> $(document).ready(function(){ $('input').keyup(function(e){ if(e.which==39) $(this).closest('td').next().find('input').focus(); else if(e.which==37) $(this).closest('td').prev().find('input').focus(); else if(e.which==40) $(this).closest('tr').next().find('td:eq('+$(this).closest('td').index()+')').find('input').focus(); else if(e.which==38) $(this).closest('tr').prev().find('td:eq('+$(this).closest('td').index()+')').find('input').focus(); }); }); </script>
When I click on the date1 input field and press the navigation key to the right, I get input field 1. This is normal.
If, for example, in the amount1 field, I enter the wrong quantity and want to fix it, I try to press the left navigation key and want to move to the desired character. However, I get the input field date1.
Question. . What will be the javascript code to get behavior like MS Excel (if I press the F2 key and then the left / right arrow key, I move one character left / right if I press the exit key and then left / right arrow, I go to next input field)?
source share