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

Inserting data from one textarea to multiple records.

Status
Not open for further replies.

Em001

Programmer
Jan 29, 2002
1
US
Hi,

I have a doosy...

I have a textarea field that collects multiple lines (list) of the same information.

e.g.

John
Jane
Mary
Joe
Sylvster
Tweety

All this is entered all at once in bulk, and seperated via the carraige-return/enter key. I need to seperate the list in the TEXTAREA so I can put each of the names into thier own record in the database. Each of the names will be going into the firstname field of each record.

Any Ideas?

Thanks,

Emm001
 
Just use any of the CF list functions and specify the delimiter, which in this case is a 'newline'). A 'newline' varies from platform to platform:

Windows: chr(10) & chr(13)
UNIX: chr(10)
Macintosh: chr(13)

I'm not sure what the newline is when the browser is on one platform and the server is on another. You'll have to experiment. Assuming that the newline is created on the client, here is an example of what your code could do (I'm going to call the textarea form field "people" for this discussion):

<!---everything between the CFSCRIPT tags could/should be in application.cfm--->
<cfscript>
win_newline = chr(10) & chr(13);
unix_newline = chr(10);
mac_newine = chr(13);

if (ReFindNoCase(&quot;Windows&quot;, CGI.http_user_agent)) {
newline = win_newline;
}
else if (ReFindNoCase(&quot;Macintosh&quot;, CGI.http_user_agent)) {
newline = mac_newline;
}
else {
newline = unix_newline;
}
</cfscript>

<br>
<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;#listlen(people, newline)#&quot;>
<!--- put the database operations here. For this example, we just print out the names --->
#listgetat(people, i, newline)#<br>
</cfloop>



 
Assuming that the textarea is named field, the following snippet will print out each name on a separate line.

Code:
<cfoutput>
   <cfloop list=&quot;#form.field#&quot; index=&quot;value&quot; delimiters=&quot;#chr(10)#&quot;>
      #value# <br> 
   </cfloop>
</cfoutput>

Since we're able to get each name into a separate item, we can do whatever we want from then on.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top