PDA

View Full Version : One Text Box = Textbox 1 Value + Textbox 2 Value


07mackenzie
09-10-2006, 12:43 AM
Hi,

I'm trying to make it so that the username field on my phpBB board is automatically set by the first and last name of the user. (I'm asking here, because its all HTML with what Im interested in)

So I have:
First Name: [textbox1]
Last Name: [textbox2]

Username: [textbox3]



How can I make it so that once First and Last name fields are filled, textbox 3 Username value will now be [textbox1 textbox2]


So example, if the user fills out the following information:
First Name: [John]
Last Name: [Doe]

So the username should fill out as
Username: [John Doe]

(with a space in between first and last name). And also, how can I make sure that Username (textbox3) is not editable? So that its value can only be changed when the other two are changed?

I don't mind using a button or whatever to make the function happen, but it would be coolest if it updated as it was typed.

Thanks!

blackpepper
09-10-2006, 12:48 AM
this is basically some javascript.. id use a server side fallback because i could just disable javascript, edit the 3rd box, and then re-enable. Anyway, this is basically setting values of textboxs with js, so look into form handeling in javascript. do you want a code sample, or were you looking to code it yourself?

07mackenzie
09-10-2006, 12:54 AM
Thanks for the quick response! A coding sample would be great (as I really do not know much about javascript)

Thanks again :)

blackpepper
09-10-2006, 12:56 AM
gimme a few minutes and ill see what i can do.

blackpepper
09-10-2006, 01:24 AM
sry but i cant really write the code at the moment,, this link is basically what your trying to do, its changing the values of a textfield.. you want to grab the 2 original values with document.formname.inputname.value; and then setting the username.value='' + val1 + '' + val2 + '';
http://www.webmonkey.com/webmonkey/98/04/index3a_page3.html
http://www.codetoad.com/javascript/enable_disable_form_element.asp

post if you have trouble or if your already lost.. sry

07mackenzie
09-10-2006, 11:03 AM
Alright, thanks very much for the help :) I'll try this out