ASP to choose between field 1 or field 2

Posted on 2007-12-05
Last Modified: 2012-06-27
Is there a way to ask a ASP script to grab an email from one field or another.

example: strform = request.form("email1") OR request.form("email2")  

or maybe use an if command, but how?

dim strfrom
if request.form("email1") = "" then use request.form("email2")
end if

depending if section 2 or section 3 is filled, i only need one email address but it can only be from if email1 box is fill or email2 box. How can I write this?
Question by:clubzone
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
  • 2
LVL 25

Expert Comment

ID: 20416987
dim strfrom
if request.form("email1") <> "" then
  strform = request.form("email1")
  strform = request.form("email2")
end if

Author Comment

ID: 20419182
thanks what if I need to do the same but including html, like so:

dim strfrom
if Request.Form("firstname_from") & Request.Form("lastname_from") <> "" then
  strform = Request.Form("firstname_from") & "." & Request.Form("lastname_from") & "" & " <" & strReturnEmailAddress & ">"
  strform = Request.Form("firstname_to") & "." & Request.Form("lastname_to") & "" & " <" & strReturnEmailAddress & ">"
end if


Accepted Solution

VoxEcho earned 250 total points
ID: 20420021
are you saying that that code doesn't work? asside from not having an open tag on either of the HTML strings, i see no problems. however personally i like assigning variables rather then pulling from the form objects repeatedly

dim email1   : email1 = request.form("email1")
dim email2   : email2 = request.form("email2")
dim cFirstFrom : cFirstFrom = request.form("firstname_from")
dim cLastFrom : cLastFrom = request.form("lastname_from")
dim cFirstTo  : cFirstTo = request.form("firstname_to")
dim cLastTo  : cLastTo = request.form("lastname_to")
dim cEmail
dim cName

if(email1<>"") then
 cEmail = email1
elseif(email2<>"") then
 cEmail = email2
end if

if(cEmail <>"") then
  if(cFirstFrom <> "" and cLastFrom <> "") Then
   cName = "<" & strReturnEmailAddress & ">" & cFirstFrom & "." & cLastFrom & "" & "</" & strReturnEmailAddress & ">"
  ElseIf(cFirstTo<>"" and cLAstTo<>"") Then
   cName = "<" & strReturnEmailAddress & ">" & cFirstTo & "." & cLastTo & "" & "</" & strReturnEmailAddress & ">"
  End IF  
End IF
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Closing Comment

ID: 31413045
thanks, the code works previously, but I needed to know how to put it together when having more fields with html commands.

objCDOMail.From = cEmail       would that be correct?

Author Comment

ID: 20420980
never mind the objCDOMail.From = cname

I figured it out :)

Expert Comment

ID: 20422813
yes, cEmail should work. you can also put the real name in as well [i believe it's]

objCDOEmail.From = cFirstFrom & " " & cLastFrom & "<" & cEmail & ">"
' // Bubba Gump <>

which will result in the real name being shown in the from field of most email programs.

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tools for analysis of code 4 49
Debugging Html 8 32
Use "if not" in a condition 2 19
[form-control] Retain values after a POST action 21 35
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 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