?
Solved

Reading data from textarea line by line - need to loop

Posted on 2007-11-13
3
Medium Priority
?
716 Views
Last Modified: 2008-02-01
I'm writing a script in VBScript for a classic ASP application (NOT ASP.NET), and I hope someone here has succeeded in this.

What I'm doing involves a form which posts to a script which will take the data and compose/send an email using CDONTS (it's on a Win2K server, IIS 5.0). The idea is to be able to paste a list of email addresses separated by \n into the textarea.  When the form is submitted, the handling script uses a Do While... Loop to extract the first line (email address) from the textarea, compose and send an email message, and then loop to the second line, compose and send a message, loop, etc. until it reaches the end.

I have this successfully working using a text file on the server containing the email addresses using the FileScriptingObject in ASP (opening the file for reading using OpenAsTextStream) instead of the textarea method, and it works fine.  There's nothing wrong with the script itself at this point, other that that I can't figure out how to extract the contents of the textarea one line at a time so that I can use the Do While... Loop.

I know I could make it a two step process by writing the contents of the textarea to a text file on the server, and then using the OpenAsTextStream method to call it back into the script.  It just seems like I should be able to do this without having to write to a file.

Any ideas?  I'm probably missing something obvious, but 20 pages of a Google search didn't give me anything.
0
Comment
Question by:mallowguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 20277952
<%@language="javascript"%>
<% //This is hielo.asp



if( "undefined" != String(Request("emailList")) )
{
      var addresses = String(Request("emailList"));
      addresses = addresses.split("\n");

      var emailObj = null;

      for(var i=0; i < addresses.length; ++i)
      {
            if(addresses[i].indexOf("@") > -1)
            {
                  var emailObj = Server.CreateObject("CDONTS.NewMail");
                  emailObj.To = addresses[i];
                  emailObj.From="you@yourdomain.com";
                  emailObj.Body="Test";
                  emailObj.BodyFormat=0;//0=HTML;1=plaintext
                  emailObj.send();
                  emailObj=null;
            }
      }
}
%>


Your form will need the following textarea:
<form action="hielo.asp" method="post">
      <textarea name="emailList"></textarea>
      <input type="submit" name="send" value="Submit"/>
</form>
0
 
LVL 4

Accepted Solution

by:
swinslow earned 500 total points
ID: 20281593
On the page that is processing your form (SendMail.asp or whatever)

  'Your send to form field
  SendToList = Request("SendTo")
  'Chr(13) is a line break
  SendToArrr = Split(SentToList,chr(13))
  For x = 0 to UBound(SendToArr)
     'All your mail sending code
     'The SendTo address will be
     'SendToArr(x)
  Next
0
 

Author Comment

by:mallowguy
ID: 20282070
Thanks to swinslow... hit on exactly what I was looking for.  I figured that splitting with the newline and writing the texarea contents to an array was going to be the answer, but for some reason it just wasn't clicking for me.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question