I have a form with 4 text boxes for IPv4 addy entry that I want to have focus move to the next text field when the user presses the period ascii # 46.
The following JS/jQ (which I basically lifted from: Move Cursor to next text Field pressing Enter) works for ascii codes for enter (13), esc, and even the space char (32):
<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 fire for regular printing ascii codes like 46 .
. How can the code be modified to allow regular ascii printing chars to initiate the field tab when pressed?
HTML input field that fires fine with ascii control chars but not printing chars
<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
?>
Referring to: https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes, the keycode for period .
is 190 and not 46. The keycode for 46 refers to the DEL key according to the same page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With