Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Jun 2003
    Location
    Kearney, Nebraska, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting information from CheckBoxes

    I am trying to use CDONTS to take information from a form (http://www.scorecentralnebraska.org/...OnlineForm.asp) and send it in an e-mail back to myself. My problem is that I cannot figure out how to pull information from the checkboxes and get them into the body of my message. If anybody has any advise that would be great. Many thanks in advance!

    The following is the code from the form:
    ----------------
    <td align="right" valign="top" class="main_content_text">9. Race (mark one or more)</td>
    <td valign="top" class="main_content_text">


    <input name="RaceA" type="checkbox" id="RaceA" value="Native American">
    Native American or Alaskan Native

    <input name="RaceB" type="checkbox" id="RaceB" value="Asian">
    Asian

    <input name="RaceC" type="checkbox" id="RaceC" value="Black or African American">
    Black or African American

    <input name="RaceD" type="checkbox" id="RaceD" value="Native Hawaiian or Other Pacific Islander">
    Native Hawaiian or other Pacific Islander

    <input name="RaceE" type="checkbox" id="RaceE" value="White">
    White</p>
    </td>
    ----------------

    The next code is what I'm using to send the actuall e-mail with. This is located on the same page above the form.
    ----------------
    <%@LANGUAGE="VBSCRIPT"%>
    <%
    if (cStr(Request("Submit")) <> "") Then

    Dim objCDO
    Dim MessageBody
    Dim RaceA1

    Set objCDO = Server.CreateObject("CDONTS.NewMail")
    objCDO.From = Request("Email")
    objCDO.To = "freemans@intellicominc.com"
    objCDO.CC = ""
    objCDO.Subject = "Webform Request for Counseling"

    MessageBody = "The following was submitted from the website on " & Now() & CHR(13)
    MessageBody = MessageBody & "---------------------------------------------" & CHR(13)
    MessageBody = MessageBody & "Name: " & Request("Name") & CHR(13)
    MessageBody = MessageBody & "Home Phone:" & CHR(13)
    MessageBody = MessageBody & "Business Phone:" & CHR(13)
    MessageBody = MessageBody & "Fax:" & CHR(13)
    MessageBody = MessageBody & "E-Mail" & CHR(13)

    **** Here is where the code would go to include the information from the Checkboxes ****

    objCDO.Body = MessageBody
    objCDO.Send()
    Set objCDO = Nothing
    Response.Redirect("http://www.scorecentralnebraska.org/index.html")

    End If
    %>

    Any help would be greatly appreciated!

    Thanks,
    Shane

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting information from CheckBoxes

    The thing to remember about checkboxes is that if they're not checked, they won't show up in the Request.Form collection at all.

    So if its value is "on", it's checked - otherwise it's not.

    You can use:
    If Request.Form("RaceA") = "on" Then
    'It's true
    Else
    'It's false
    End If

  3. #3
    New Lounger
    Join Date
    Jun 2003
    Location
    Kearney, Nebraska, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting information from CheckBoxes

    I tried adding the following code, all on one line, but when I check RaceA in the form it always comes back with "false" in the message body. Any idea suggestions? I've attached the entire asp file if that helps any. Thanks for your help!

    Shane

    ------------
    if Request.Form("RaceA")="On" Then MessageBody = MessageBody & "True" & CHR(13) Else MessageBody = MessageBody & "False" & CHR(13)
    ------------

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting information from CheckBoxes

    DOH!

    Sorry for the oversight on my part. Add the name="" attribute to the Checkbox items on your HTML page (like <input type="checkbox" id="RaceA" name="RaceA" value="...">)

    Hope this helps!

  5. #5
    New Lounger
    Join Date
    Jun 2003
    Location
    Kearney, Nebraska, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting information from CheckBoxes

    I think it's already there...
    -------
    <input name="RaceA" type="checkbox" id="RaceA" value="Native American">
    Native American or Alaskan Native
    -------
    Does it matter what order they're in or do id and name have to be different?

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting information from CheckBoxes

    My bad - I got in such a hurry that i forgot to read through the code you sent!

    I'm a little out of touch with Classic ASP at the moment - I've been using ASP.NET for quite a while now and I've honestly forgotten a lot of the details (like handling checkboxes).

    You may want to check out one of my favorite ASP resources: W3 Schools. Specifically, they have a page that talks about handling checkbox input: http://www.w3schools.com/asp/asp_ref_request.asp and the demo:
    http://www.w3schools.com/asp/showasp.asp?f...demo_checkboxes

    Sorry for the confusion <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Getting information from CheckBoxes

    You've changed the default value from On to Native American. You can see what effect this has with this test page (which you should name chkbx.asp so it calls itself):

    <html>
    <head>
    <title>ASP Checkbox processing test</title>
    </head>

    <body>
    <h3>A Wee Test of ASP Handling of HTML Checkboxes</h3>
    <%
    If Request.Form("cbWhatever") <> "" Then
    Response.Write "

    The checkbox was checked! Its value is: " & Request.Form("cbWhatever") & _
    "
    (make a note of it!)</p>" & vbCrLf
    Else
    Response.Write "The checkbox was not passed to me.</p>" & vbCrLf
    End If
    %>
    <hr>

    <form method="POST" action="chkbx.asp">
    <input type="checkbox" name="cbWhatever" value="Just Testing">Check me and
    submit! Or don't check me. What do I care?


    <input type="submit" value="Submit" name="B1"></p>
    </form>

    </body>
    </html>

  8. #8
    New Lounger
    Join Date
    Jun 2003
    Location
    Kearney, Nebraska, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting information from CheckBoxes

    Thanks to both of you for the information. After realizing some early mistakes, mainly changing the default value, I figured out what I had done wrong and managed to get everything working. Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •