Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have 3 text fields for the user to enter a phone number. Each one is set to max of each phone number segment - ( xxx xxx xxxx)3,3,4

How do I change this code to do this? It works by using the Tab key but I'd like it to jump when it hits the max character length:

<label for="P1" class="CstmFrmElmntLabel">Owner Phone</label>  
                
                <input name="P1" type="text" id="P1" size="6" class="CstmFrmElmntInputi29" onfocus="javascript:this.className = 'CstmFrmElmntInputi29NavSel';" onblur="javascript:this.className = 'CstmFrmElmntInputi29';" onmouseover="window.status = 'Owner\'s Phone Number: Area Code';
                        return true;" onmouseout="window.status = '';
                        return true;" title="Owner's Phone Number: Area Code" value="<? echo $P1; ?>" maxlength="3" onkeyup="AEV_set_tel_number('Phone_Number', 'P');"/>
                                                      
                <input name="P2" type="text" id="P2" size="6" class="CstmFrmElmntInputi29" onfocus="javascript:this.className = 'CstmFrmElmntInputi29NavSel';" onblur="javascript:this.className = 'CstmFrmElmntInputi29';" onmouseover="window.status = 'Owner\'s Phone Number: Prefix';
                        return true;" onmouseout="window.status = '';
                        return true;" title="Owner's Phone Number: Prefix" value="<? echo $P2; ?>" maxlength="3" onkeyup="AEV_set_tel_number('Phone_Number', 'P');" />
                                 
                <input name="P3" type="text" id="P3" size="8" class="CstmFrmElmntInputi34" onfocus="javascript:this.className = 'CstmFrmElmntInputi34NavSel';" onblur="javascript:this.className = 'CstmFrmElmntInputi34';" onmouseover="window.status = 'Owner\'s Phone Number: Suffix';
                        return true;" onmouseout="window.status = '';
                        return true;" title="Owner's Phone Number: Suffix" value="<? echo $P3; ?>" maxlength="4" onkeyup="AEV_set_tel_number('Phone_Number', 'P');" />
                        
                <input type="hidden" name="Phone Number" id="Phone_Number" value="<? echo $Phone; ?>" />
                <br />


What I have tried:

I'm not sure what to do yet. I'm pretty new to php and just learning and thought I'd tackle this in the code that exists already.
Posted
Updated 17-Jul-17 23:15pm

1 solution

There is nothing built in, but the actual code is fairly simple...
All you need is to add value to the maxlength[^] attribute and do some code...
A jQuery based example:
JavaScript
$( "input[maxlength]" ).keyup(function() {
    var maxLen = this.maxLength;
    var currentLen = this.value.length;

    if (maxLen === currentLen)
    {
        $(this).next().focus();
    } 
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900