ashrobbins87 Posted April 9, 2009 Share Posted April 9, 2009 Is it possible to dynamically populate a text field, based on the content of other text fields on the same page? For example I have a firstname field and a surname field, and I want to populate a username field with the first letter of the firstname and the first 7 letters of the surname so that the user can see it. firstname: ashley surname: robbins username: arobbins Can this be done?? Quote Link to comment https://forums.phpfreaks.com/topic/153334-solved-dynamically-populate-text-field/ Share on other sites More sharing options...
wildteen88 Posted April 9, 2009 Share Posted April 9, 2009 if this is done while the user is typing their first/surename you wont be able to do this with PHP. You'll have to use javascript for this. Quote Link to comment https://forums.phpfreaks.com/topic/153334-solved-dynamically-populate-text-field/#findComment-805557 Share on other sites More sharing options...
ashrobbins87 Posted April 9, 2009 Author Share Posted April 9, 2009 Ok great at least I now know its possible. I take it this can be done without the need to refresh the page? Can anyone point me in the direction of where to start?? Quote Link to comment https://forums.phpfreaks.com/topic/153334-solved-dynamically-populate-text-field/#findComment-805561 Share on other sites More sharing options...
mrMarcus Posted April 9, 2009 Share Posted April 9, 2009 you will most likely needs things like getElementById() and onChange() / onKeyUp() .. those are in the javascript library. javascript has string length functions like PHP, so you can use that to get the appropriate number of letters from the name(s) and then join them. i'd actually say, look into AJAX and PHP to get this done if you are already with PHP. Quote Link to comment https://forums.phpfreaks.com/topic/153334-solved-dynamically-populate-text-field/#findComment-805661 Share on other sites More sharing options...
ashrobbins87 Posted April 9, 2009 Author Share Posted April 9, 2009 Thanks guys for the help, I've sorted it now and you're right I had to use byElementID and onKeyUp Quote Link to comment https://forums.phpfreaks.com/topic/153334-solved-dynamically-populate-text-field/#findComment-805714 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.