OriginalBoy Posted July 11, 2008 Share Posted July 11, 2008 Hey, How do i do this? I want it so it will work for a phone number Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 11, 2008 Share Posted July 11, 2008 You're going to need to provide a better explanation of what you want. Are you wanting to have the form "auto-tab" from one field to another (based upon what?), are you wanting to convert 8001234567 to 800-123-4567, or what? Quote Link to comment Share on other sites More sharing options...
OriginalBoy Posted July 11, 2008 Author Share Posted July 11, 2008 Yes I want it to go to the next field when they ave reached the maxlength (3) Quote Link to comment Share on other sites More sharing options...
adam84 Posted July 11, 2008 Share Posted July 11, 2008 put a key event (onkeyup, etc) event on the textfield, then when the text length is three or whatever box your on, use the .focus on the next textfield to wanna jump to Quote Link to comment Share on other sites More sharing options...
OriginalBoy Posted July 11, 2008 Author Share Posted July 11, 2008 Errr sorry I don't understand ive never done javascript before. Can I have the code i need to use. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 11, 2008 Share Posted July 11, 2008 <html> <head> <script type="text/javascript"> function moveNext(fieldObj, nextFieldID) { if (fieldObj.value.length >= fieldObj.maxLength) { document.getElementById(nextFieldID).focus(); } } </script> </head> <body> Phone: (<input type="text" maxlength="3" size="2" id="area_code" name="area_code" onkeyup="moveNext(this, 'prefix');">) <input type="text" maxlength="3" size="2" id="prefix" name="prefix" onkeyup="moveNext(this, 'phone');"> - <input type="text" maxlength="4" size="3" id="phone" name="phone" onkeyup=""><br> </body> </html> Quote Link to comment Share on other sites More sharing options...
OriginalBoy Posted July 11, 2008 Author Share Posted July 11, 2008 <td>Home Phone: <td> <input type="hidden" name="homephone" id="homephone" /> (<input type="text" name="hphone1" size="3" maxlength="3" onkeyup="moveNext(this, 'hphone2');">)-<input type="text" name="hphone2" size="3" maxlength="3" onkeyup="moveNext(this, 'hphone3');">-<input type="text" name="hphone3" size="4" maxlength="4" onkeyup=""></td> </tr> I put that in and then the top thing at the top of my page and its not worked. What have I done wrong? Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 12, 2008 Share Posted July 12, 2008 The code I provided requires you to pass the ID of the field to move to. You didn't set IDs for the fields: <td>Home Phone: <td> <input type="hidden" name="homephone" id="homephone" /> (<input type="text" name="hphone1" size="3" maxlength="3" onkeyup="moveNext(this, 'hphone2');">)-<input type="text" name="hphone2" id="hphone2" size="3" maxlength="3" onkeyup="moveNext(this, 'hphone3');">-<input type="text" name="hphone3" id="hphone3" size="4" maxlength="4" onkeyup=""></td> </tr> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.