Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining Form Fields

Status
Not open for further replies.

penguinspeaks

Technical User
Nov 13, 2002
234
0
16
US
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?
 
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?
 
Code:
f.username_.value = f.fname[red].value[/red] + f.lname.value;
 
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.
 

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
 
Ok thanks for the reply. My expectations were high on this anyway.

Thanks guys!
 
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
 
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.
 
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);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top