Cannot focus the next input field using ascii 46 `.` (period)

I have a form with 4 text fields for an IPv4 addy entry in which I want the focus to move to the next text field when the user presses the ascii # 46 period.

The following JS / jQ (which I basically shot from: Move the cursor to the next text Field, press Enter ) works for ascii codes for input (13), esc, and even char (32) space:

<script language ="javascript" type="text/javascript" >
    function ipfNext() {
      //alert( 'FUNC ipfNext' );
      $( document ).ready( function()  {
        $( '#formContent .inputTextIpf').keydown( function( e )  {
          if( e.keyCode == 46 ) {
            $( ':input:eq(' + ( $( ':input' ).index( this ) + 1 ) + ')' ).focus();
            return false;
          } // close IF 
        }); // close FUNC e
      }); // close docReady FUNC
    } // close FUNF ipfNext
  </script>

but it doesn't seem to work for regular ascii printed codes like 46 .. How can I change the code so that regular ascii print characters trigger a field tab when clicked?

HTML input field that works fine with ascii control characters but doesn't print characters

<input type="text" id="ipf1" name="ipf1" class="inputTextIpf" maxlength="3" onkeyup="return ipfNext();" value=
        <?php
        if ( !empty( $_SESSION[ 'ipf1' ] ) ) {
          echo '"' . $_SESSION[ 'ipf1' ] . '"> . ';
        } else {
          echo '""> . ';
        } // close IF
      ?>
+6

Source: https://habr.com/ru/post/1016191/


All Articles