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

e-mail if check box is checked

Status
Not open for further replies.

edgarv

MIS
Jul 25, 2003
248
US
Hello,

After many tries and with all your help I finally have my webform working.
Now I have a new problem, how can I send an e-mail when somebody checks a box? or would that be a javascript issue?
 
Basically you owuld want a form submission. First page would have the checkbox and any other relevant information you need form the user. The second page would be mostly ASP/server-side. First check if the checkbox value was passed in the form (the value is only passed when the box is checked, otherwise it will be an empty value). Then use something like CDOSYS (or CDONTS if your on NT, or any of several 3rd party objects if available, like JMail, ASPMail, etc) to send the email.

barcode_1.gif
 
but how would I go about building the code for it?
 
Well, your form would be something like:
Code:
<html>
<body>
<form method="POST" action="myPage2.asp">
Email Address: <input type="text" name="txtEmail" /><br/>
Would you liek me to email you? <input type="checkbox" name="chkEmail" value="yes" /><br/>
<input type="submit" value="Go!" />
</form>
</body>
</html>

And the your 2nd page would look something like:
Code:
<%
Option Explicit

'Do they want an email?
If Request.Form("chkEmail") <> "" Then
   'is the email address filled in?
   If Request.Form("txtEmail") = "" Then
      'no email!
      Response.Write "You didn't enter your email address and I can't read minds today, sorry."
      Response.End
   End If

   'checked and address submitted, lets send it
   'Copied From: [url=http://www.w3schools.com/asp/asp_send_email.asp] W3Schools.com[/url]
   Set myMail=CreateObject("CDO.Message")
   myMail.Subject="Sending email with CDO"
   myMail.From="mymail@mydomain.com"
   myMail.To=Request.Form("txtEmail")
   myMail.TextBody="Hi There! This is me message to you! Thanks for checking my checkbox."
   myMail.Send
   set myMail=nothing

   Response.Write "Your email has been sent."
Else
   Response.Write "Since you didn't check the checkbox, I didn't email you. Thanks anyways."
End If
%>

The W3Schools link has a bunch of examples of using the CDO.Message object's differant properties. Obviously my above example was a litle simplified (you may want more fields, a better email validation, etc), but I hope it was along the lines of what you were looking for.

-T

barcode_1.gif
 
If you have it installed, or can install it, jmail is a free and very easy to use alternative. Their documentation is very good too - you can modify their examples in no time to get working code.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top