INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Combining Form Fields

Combining Form Fields

(OP)
Now that my form is actually working, and thanks again everyone for the great help, I do have another question.

I am writing a form to enter users into a database table. This will be completed by a supervisor for a few different reasons.
What I want this form to do is create the username on the fly by taking the first name, last initial, and the birth year.

If it is a supervisor, this format does not have to be the same as an employee so I do have a check box asking if the username should be "auto crated". Here is the code I have so far:

CODE


<script type="text/javascript">
function FillUser(f) {
  if(f.createuser.checked == true) {
    f.username_.value = f.fname+f.lname.value;
   
  }
}
</script>

this was used to try and combine the fields of first and last names, but this gave me
[code][object HTMLInputElement]"whatever the last name was in the field" so I know the code is incorrect.

my fields are fname  lname  and dob_  is there a way to combine these in the fashion that I want it?

RE: Combining Form Fields

(OP)
Now that my form is actually working, and thanks again everyone for the great help, I do have another question.

I am writing a form to enter users into a database table. This will be completed by a supervisor for a few different reasons.
What I want this form to do is create the username on the fly by taking the first name, last initial, and the birth year.

If it is a supervisor, this format does not have to be the same as an employee so I do have a check box asking if the username should be "auto crated". Here is the code I have so far:

CODE

<script type="text/javascript">
function FillUser(f) {
if(f.createuser.checked == true) {
f.username_.value = f.fname+f.lname.value;

}
}
</script> 

this was used to try and combine the fields of first and last names, but this gave me

CODE

[object HTMLInputElement]"whatever the last name was in the field" 
so I know the code is incorrect.

my fields are fname lname and dob_ is there a way to combine these in the fashion that I want it?

RE: Combining Form Fields

CODE

f.username_.value = f.fname.value + f.lname.value; 

RE: Combining Form Fields

(OP)
Awesome but if I only wanted to use the first letter of the last name? So my name would be JeffF1969 based on the criteria presented.
It would be the first name, First letter of last name, and the 4-digit year of birth. which is in the DOB field.

And your help is most appreciated.

RE: Combining Form Fields


Quote:

so I know the code is incorrect.
It isn't.

You can't concatenate an object reference (f.f_name) and a object's value (f.l_name.value) and get the right answer.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Combining Form Fields

(OP)
Ok thanks for the reply. My expectations were high on this anyway.

Thanks guys!

RE: Combining Form Fields

Quote:

Ok thanks for the reply

But have you seen where the error is??

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Combining Form Fields

(OP)
If you are referring to the error in what I was doing, then yes. I see that you have to concatenate the "values" of both. I was close anyway.

I actually did not understand your first reply, so I replied as to say that I could not get a first letter and so forth.

RE: Combining Form Fields

CODE

f.username_.value = f.fname.value + f.lname.value.substring(0,1); 

no idea about your dob field as you don't show its format. assuming its yyyy-mm-dd it would be

CODE

f.username_.value = f.fname.value + f.lname.value.substring(0,1) + f.dob.value.substring(0,4); 

if dd-mm-yyyy

CODE

f.username_.value = f.fname.value + f.lname.value.substring(0,1) + f.dob.value.substring(6); 

RE: Combining Form Fields

(OP)
This is precisely what I needed.

Thank You so much!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close