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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I split the data from 1 feild in a form? 1

Status
Not open for further replies.

scottew

IS-IT--Management
Mar 6, 2003
492
US
I have a from with two fields (name and email). When this page is submitted, it brings them to another page and I would like to split the name field into two fields (firstname and lastname).

Code:
<INPUT TYPE="text" NAME="name" SIZE="40" maxlength="40">
<INPUT TYPE="text" NAME="email" SIZE="40" maxlength="40">

Code:
<cfoutput><INPUT TYPE="text" NAME="firstname" SIZE="40" maxlength="40" value="#form.name#"></cfoutput>

<cfoutput><INPUT TYPE="text" NAME="lastname" SIZE="40" maxlength="40" value="form.#name#"></cfoutput>

<cfoutput><INPUT TYPE="text" NAME="email" SIZE="40" maxlength="40" value="#form.email#"></cfoutput>

Any tips on how I can accomplish this would be appreciated.

Thanks,
Scott



 
Well, the best way would be have the name field as two field names instead of one. Not sure if that is doable or not. But I guess you can also do something like:

<cfset firstname = ListFirst(name," ")>
<cfset lastname = ListLast(name," ")>

Play around with that...

____________________________________
Just Imagine.
 
Thanks GUJUm0del, but where would I set those variables, on the first page.
 
One the page where your parsing the fields.

Code:
<cfset fname = ListFirst(#FORM.name#," ")>
<cfset lname = ListLast(#FORM.name#," ")>

<cfoutput>
<INPUT TYPE="text" NAME="firstname" SIZE="40" maxlength="40" value="#fname#">

<INPUT TYPE="text" NAME="lastname" SIZE="40" maxlength="40" value="#lname#">

<INPUT TYPE="text" NAME="email" SIZE="40" maxlength="40" value="#form.email#">
</cfoutput>

NOTE: you do not need to wrap each line in it's own <cfoutptu> tag.

And, i'm sure what you posted above was a mistake but form.#name# should be #form.name# or you'll get an error.

____________________________________
Just Imagine.
 
Great thanks! Yes, that was a typo. I got that part working, I just need to parse (I couldn't think of that word earlier) the fields.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top