Solved

ASP checkbox value

Posted on 2004-04-28
16
538 Views
Last Modified: 2008-02-01
I have 50-60 checkboxes on an HTML page and am using an ASP formhandler page to gather the information from the checkboxes and send an e mail to a user with the names of the checkboxes that have a "yes" value. It works well, except the e-mail has large amount of white space where the value "no" checkboxes are taking up space, so If you check box #1 and Box#50 the e-mail recipient has to scroll to the bottom of the email to see the #50 checkbox's "name". Is there any way to get the e-mail to display only the "yes" value items without white space. I hope I'm explaining this properly.
0
Comment
Question by:CementTruck
  • 5
  • 4
  • 4
  • +1
16 Comments
 
LVL 4

Expert Comment

by:dukestaTAI
ID: 10938194
Post you code.  You need to loop through your code and skip any checkboxes that are not checked by writing nothing.
0
 
LVL 4

Expert Comment

by:lpzCoville
ID: 10938216
Sure, but it would be easier to comment if you post your code.

Let's say you are using something like

    For Each x in Request.Form
        strMsgText = strMsgText & vbcrlf & x & " is " & Request.Form(x)
    Next

then change it to something like

    For Each x in Request.Form
        If Request.Form(x) = "on" Then
            strMsgText = strMsgText & vbcrlf & x & " is " & Request.Form(x)
        End If
    Next


0
 

Author Comment

by:CementTruck
ID: 10938328
The portion below shows how the strbody name requests the specific checkbox name.

strBodyACRYLIC      = Request.Form("ACRYLIC")
strBodyCELAZOLE      = Request.Form("CELAZOLE")
strBodyCLEAR_PVC      = Request.Form("CLEAR_PVC")


The portion below shows how the strbody name is "harvested" and put into e-mail form.

& " " &  strBodyACRYLIC       & " <br>" & vbCrLf _
& " " &  strBodyCELAZOLE     & " <br>" & vbCrLf _       
& " " &  strBodyCLEAR_PVC   & " <br>" & vbCrLf _

As the coding reflects, I am a novice at this. I'm sure there are some easier/cleaner ways to create these pages
0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10938417
You could easily do what you are looking for like this:

For Each item In Request.Form
If Item <> "" then
Response.Write item & "<BR>"
ENd if
Next

Next
0
 

Author Comment

by:CementTruck
ID: 10938631
Q: to Slimshaneey,

can you create an example using one of the lines of code from the previous comments? It sounds like you want me to try this:

strBodyACRYLIC     = Request.Form("ACRYLIC") If Item <> "" then Response.Write item & "<BR>" ENd if
strBodyCELAZOLE     = Request.Form("CELAZOLE")  If Item <> "" then Response.Write item & "<BR>" ENd if
etc
etc
etc

Is there supposed to be a value in between the <>?
0
 
LVL 4

Expert Comment

by:lpzCoville
ID: 10938639
Well, it depends on what else you have in your form.  If ALL you have in the form is these 50 checkboxes, then

    strbody = "Hi!" & vbCrLf & vbCrLf & "you requested info on the following products:" & vbCrLf   'or whatever
    For Each x in Request.Form
        If Request.Form(x) = "on" Then
            strbody = strbody & vbcrlf & x & " is " & Request.Form(x)
        End If
    Next
    strbody = strbody & vbCrLf & "Have a nice day" 'or whatever"

will work fine, and save you a lot of trouble if you add/change checkboxes.  probably that is not the case however; so I would suggest naming all the checkboxes that have this sort information with a a uniform prefix that the form handler can test for.  For example:

<input type="checkbox" name="paintsCRYLIC">
<input type="checkbox" name="paintsCELAZOLE">

Then you can compose the strbody, which probably includes infomation from other fields in the Request From, as you are doing right now, and when it gets to this part, use something like:

    For Each x in Request.Form
        If Left(x, 6) = "paints" And Request.Form(x) = "on" Then
            strMsgText = strMsgText & vbcrlf & Mid(x, 7)
        End If
    Next

I hope that helps.  If this is not clear, please ask; although again, if you post more of the code you are currently using/give a more specific idea of the context, it's easier to provide more specific help.

Good luck!
0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10938673
I suggested that loop as part of the string for the email. It will read all the inputs in the form and write them to the string. It doesnt then write extra <br>'s if there is no value

IE

For Each item In Request.Form
If Item <> "" then
EmailFormBody = EmailFormBod & Response.Write item & "<BR>"
ENd if
Next
0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10938700
Oops, typo...

For Each item In Request.Form
If Item <> "" then
EmailFormBody = EmailFormBody & Response.Write item & "<BR>"
ENd if
Next
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:CementTruck
ID: 10950220
For those requesting the code, here it is. I have tried most of the ideas that were passed on to me, but I must not have the sytax right. On the last few I tried, it kept bombing out on the word "item", saying it was undefined. So I DIM'med it, but nothing changed.

Again, if you could please inject your code into the code below it would be appreciated. I would like to try all your suggestions, if I can get them to work, and chose the one most suitable for my purposes. If you could impart more wisdome on how to clean up my code that would be great too.


<%
Option Explicit

' The list below declares major variables that will be used in this page.
Dim objCDO
Dim objCDOMail
Dim strSubject
Dim strBody

' The list below declares variable strings labeling each entry from the ASPtemplate.

Dim ACETAL
Dim ACETRON_GP
Dim ACRYLIC
Dim CELAZOLE
Dim CLEAR_PVC
Dim CPVC


' The list below declares the labels.

Dim lblACETAL
Dim lblACETRON_GP
Dim lblACRYLIC
Dim lblCELAZOLE
Dim lblCLEAR_PVC
Dim lblCPVC


' The list below shows how each entry label will appear.

lblACETAL                  = "ACETAL"
lblACETRON_GP            = "ACETRON_GP"
lblACRYLIC                  = "ACRYLIC"
lblCELAZOLE            = "CELAZOLE"
lblCLEAR_PVC            = "CLEAR_PVC"
lblCPVC                  = "CPVC"


' The list below declares strings that will be used later to combine the label and the actual item label.

Dim strBodyACETAL
Dim strBodyACETRON_GP
Dim strBodyACRYLIC
Dim strBodyCELAZOLE
Dim strBodyCLEAR_PVC
Dim strBodyCPVC

' The list below declares that the string body combines the functions from the labels, and entries from fields in the ASPtemplate.

strBodyACETAL                  = Request.Form("ACETAL")
strBodyACETRON_GP                  = Request.Form("ACETRON_GP")
strBodyACRYLIC                  = Request.Form("ACRYLIC")
strBodyCELAZOLE                  = Request.Form("CELAZOLE")
strBodyCLEAR_PVC                  = Request.Form("CLEAR_PVC")
strBodyCPVC                  = Request.Form("CPVC")



strSubject = "CATALOG REQUEST"




' The email contains customer information from the ASPtemplate.

strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf _
            & "                  <html>" & vbCrLf _
            & "                  <head>" & vbCrLf _
            & "           <meta http-equiv=Content-Type content=""text/html; charset=iso-8859-1"">" & vbCrLf _
            & "                  </head>" & vbCrLf _
            & "              <body bgcolor=""#FFFFFF"">" & vbCrLf _
            & "           <p>" & vbCrLf _
            & "             <font face=""arial"" size=""5"">" & vbCrLf _
            & "         <pCatalog Request</p>" & vbCrLf _
            & "         </p>" & vbCrLf _
                                & "          <font face=""arial"" size=""-1"">" & vbCrLf _
            & "           <p>THIS IS A SYSTEM GENERATED MESSAGE. DO NOT REPLY TO THE WEBFORMS@ALRO.COM ADDRESS.</p>" & vbCrLf _
            & "           <p><hr></p>" & vbCrLf _
            & "         <p><b>I am interested in the following:</b></p>" & vbCrLf _
            & " "             &  strBodyABS_                              & " <br>" & vbCrLf _
            & " "             &  strBodyACETAL                        & " <br>" & vbCrLf _       
            & " "             &  strBodyACETRON_GP                  & " <br>" & vbCrLf _       
            & " "             &  strBodyACRYLIC                        & " <br>" & vbCrLf _
            & " "             &  strBodyCELAZOLE                        & " <br>" & vbCrLf _       
            & " "             &  strBodyCLEAR_PVC                        & " <br>" & vbCrLf _
            & " "             &  strBodyCPVC                              & " <br>" & vbCrLf _       
            & "              </body>" & vbCrLf _
            & "            </html>" & vbCrLf      
      
      
      
      
            
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

objCDOMail.From   = "webforms@myplaceofbusiness.com"
objCDOMail.To   = "me@myplaceofbusiness.com"


objCDOMail.Subject = strSubject
objCDOMail.Body    = strBody


objCDOMail.MailFormat = 0
objCDOMail.BodyFormat = 0


objCDOMail.Send



' Set objMail = Nothing
Set objCDOMail = Nothing


%>

<HTML>

<HEAD>
            
</HEAD>

<BODY BGCOLOR="white">

<P><SCRIPT LANGUAGE="JavaScript">



<!--
 function redirect()
 {
  window.location = "../../DIVPLastics/Plastics_confirmation.htm"
 }
 
 setTimeout("redirect();", 0)
//-->


</SCRIPT>

</BODY>

</HTML>            
%>
0
 
LVL 4

Expert Comment

by:dukestaTAI
ID: 10950366
I don't see the word item anywhere in your code, defined or undefined.

Your code is fairly clean.  Your use of Option explicit is a good indicator.  Remember that blank lines are great for making code readable but one blank line is enough.
0
 
LVL 4

Expert Comment

by:lpzCoville
ID: 10950395
off the top of my head, you can drop all that html and javascript aat the end and replace it with the single line

    Response.Redirect "../../DIVPLastics/Plastics_confirmation.htm"

however, as to the original issue, can you show the html for the form that is submitting the request, also?
0
 

Author Comment

by:CementTruck
ID: 10950666
To: dukestaTAI

The last thing I tried was something mentioned earlier in the post. It looked like this -

For Each item In Request.Form
If Item <> "" then
EmailFormBody = EmailFormBody & Response.Write item & "<BR>"
ENd if
Next


It was bombing out here ....... EmailFormBody = EmailFormBody & Response.Write item & "<BR>".... and the word "item" was what it was  bombing out on. I positioned this bit of code right after the entry ....strSubject = "CATALOG REQUEST".

I also changed EmailFormBody to strbody.


------------------------------------------
to: lpzCoville

Here's the code from the submitting form. I will try the Response.Redirect you mentioned.

<form name="form1" method="post" action="FormHandler/PselectSubmit2.asp">
  <p>
    <input type="checkbox" name="ACETAL" value="ACETAL">
    <font font><a href="../DIVPlastics/Plastic_Product_Acetron.htm"><font color="000000">ACETAL</font></a><br>
    </font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="ACETRON_GP" value="ACETRON_GP">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Acetron.htm"><font color="000000">ACETRON GP<br>
    </font></a></font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="ACRYLIC" value="ACRYLIC">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Acrylic.htm"><font color="000000">ACRYLIC</font></a><br>
    </font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="CELAZOLE" value="CELAZOLE">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Celazole.htm"><font color="000000">CELAZOLE</font></a><br>
    </font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="CLEAR_PVC" value="CLEAR_PVC">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Clearpvc.htm"><font color="000000">CLEAR PVC<br>
    </font></a></font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="CPVC" value="CPVC">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Cpvc.htm"><font color="000000">CPVC</font></a></font></p>
  </form>
0
 
LVL 4

Expert Comment

by:lpzCoville
ID: 10951048
OK:

unless there is something else going on on PselectSubmit2.asp that actually uses these, you can ditch all of:

      ' The list below declares variable strings labeling each entry from the ASPtemplate.

      Dim ACETAL
      Dim ACETRON_GP
      Dim ACRYLIC
      Dim CELAZOLE
      Dim CLEAR_PVC
      Dim CPVC


      ' The list below declares the labels.

      Dim lblACETAL
      Dim lblACETRON_GP
      Dim lblACRYLIC
      Dim lblCELAZOLE
      Dim lblCLEAR_PVC
      Dim lblCPVC


      ' The list below shows how each entry label will appear.

      lblACETAL               = "ACETAL"
      lblACETRON_GP          = "ACETRON_GP"
      lblACRYLIC               = "ACRYLIC"
      lblCELAZOLE          = "CELAZOLE"
      lblCLEAR_PVC          = "CLEAR_PVC"
      lblCPVC               = "CPVC"

becasue it's just not doing anything.  further, you can get rid of:

      ' The list below declares strings that will be used later to combine the label and the actual item label.

      Dim strBodyACETAL
      Dim strBodyACETRON_GP
      Dim strBodyACRYLIC
      Dim strBodyCELAZOLE
      Dim strBodyCLEAR_PVC
      Dim strBodyCPVC

      ' The list below declares that the string body combines the functions from the labels, and entries from fields in the ASPtemplate.

      strBodyACETAL               = Request.Form("ACETAL")
      strBodyACETRON_GP               = Request.Form("ACETRON_GP")
      strBodyACRYLIC               = Request.Form("ACRYLIC")
      strBodyCELAZOLE               = Request.Form("CELAZOLE")
      strBodyCLEAR_PVC               = Request.Form("CLEAR_PVC")
      strBodyCPVC               = Request.Form("CPVC")

and change your strBody concatenation to:

    strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf _
          & "               <html>" & vbCrLf _
          & "               <head>" & vbCrLf _
          & "          <meta http-equiv=Content-Type content=""text/html; charset=iso-8859-1"">" & vbCrLf _
          & "               </head>" & vbCrLf _
          & "            <body bgcolor=""#FFFFFF"">" & vbCrLf _
          & "          <p>" & vbCrLf _
          & "            <font face=""arial"" size=""5"">" & vbCrLf _
          & "         <pCatalog Request</p>" & vbCrLf _
          & "         </p>" & vbCrLf _
                                & "          <font face=""arial"" size=""-1"">" & vbCrLf _
          & "          <p>THIS IS A SYSTEM GENERATED MESSAGE. DO NOT REPLY TO THE WEBFORMS@ALRO.COM ADDRESS.</p>" & vbCrLf _
          & "          <p><hr></p>" & vbCrLf _
          & "         <p><b>I am interested in the following:</b></p>" & vbCrLf

      If Request.Form("ABS") <> "" Then
           strBody = strBody & " " & Request.Form("ABS") & " <br>" & vbCrLf
      End If

      If Request.Form("ABS") <> "" Then
           strBody = strBody & " " & Request.Form("ABS") & " <br>" & vbCrLf
      End If

          ' etc. ...

      strBody = strBody & "            </body>" & vbCrLf _
            & "          </html>" & vbCrLf    

which will solve your original problem, your code will be more compact and easier to maintain using the following method:

1) prefix all the checkbox input names on the submoitting form with a unique, uniform prefix, ex: "chkprod" or whatever:

    <input type="checkbox" name="chkprodACETAL" value="ACETAL">
    <font font><a href="../DIVPlastics/Plastic_Product_Acetron.htm"><font color="000000">ACETAL</font></a><br>
    </font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="chkprodACETRON_GP" value="ACETRON_GP">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Acetron.htm"><font color="000000">ACETRON GP<br>
    </font></a></font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
...etc.

2) in PselectSubmit2.asp, instead of

      If Request.Form("ABS") <> "" Then
           strBody = strBody & " " & Request.Form("ABS") & " <br>" & vbCrLf
      End If

      If Request.Form("ABS") <> "" Then
           strBody = strBody & " " & Request.Form("ABS") & " <br>" & vbCrLf
      End If

 .. and so on fore each checkbox, use a loop:

    'do this at the top of the page, of course
    Dim MyChk

    For Each MyChk in Request.Form
        If Left(MyChk, 7) = "chkprod" And Request.Form(MyChk) <> "" Then
           strBody = strBody & " " & Request.Form(MyChk) & " <br>" & vbCrLf
        End If
    Next
0
 
LVL 4

Accepted Solution

by:
dukestaTAI earned 250 total points
ID: 10951080
Try giving all of you checkboxes the same name.  Then use an array to loop through the checkboxes on your action page. You will have to make some changes to the code I provided but this should get you moving in the right direction.

<form name="form1" method="post" action="FormHandler/PselectSubmit2.asp">
  <p>
    <input type="checkbox" name="chkbox" value="ACETAL">
    <font font><a href="../DIVPlastics/Plastic_Product_Acetron.htm"><font color="000000">ACETAL</font></a><br>
    </font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="chkbox" value="ACETRON_GP">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Acetron.htm"><font color="000000">ACETRON GP<br>
    </font></a></font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="chkbox" value="ACRYLIC">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Acrylic.htm"><font color="000000">ACRYLIC</font></a><br>
    </font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="chkbox" value="CELAZOLE">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Celazole.htm"><font color="000000">CELAZOLE</font></a><br>
    </font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="chkbox" value="CLEAR_PVC">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Clearpvc.htm"><font color="000000">CLEAR PVC<br>
    </font></a></font><a
        href="http://www.alro.com/plastic_product_abs.htm"><font color="000000" font>
    <input type="checkbox" name="chkbox" value="CPVC">
    </font></a><font font><a href="../DIVPlastics/Plastic_Product_Cpvc.htm"><font color="000000">CPVC</font></a></font></p>
  </form>

Action page:

Dim chkbox(2) 'This number should be set the numer of items in your array The list your array items below
      chkbox(1) = "Put you values here1"
      chkbox(2) = "Put you values here2"
                  
If Request.Form("chkbox") = "" then
      
          'Do nothing      

Else      
   thisDelete = 1
                        
    For i = 1 to 6
      if chkbox(i) = chkbox(i).item(thisDelete) then
            
                          'Write the checkbox info here

            if thisDelete < chkbox(i).Count then
                  thisDelete = thisDelete + 1
                      end if
      End If
    Next
End If      
0
 

Author Comment

by:CementTruck
ID: 10959256
Thank you all who participated. I have tried all your suggestions but had some difficulties with them. I have archived all your suggestions and will keep tryig all of them for future use on our site.

I ended up using a simpler method that delimits each checkbox name with a comma. First, I DIM'med

Dim chkbx
Dim strbodychkbx

then,

strbodychkbx            = Request.Form("chkbx")

then, in the html portion of the page,

& " "       &  strBodychkbx  & " <br>" & vbCrLf _

I also changed all the checkbox' names to chkbx in the main page. The e-mail result comes out like this,

ACRYLIC, FLUOROSINT, PBT, PETG, SEMITRON

I think I can live with it for now.


I have one other question, however.

1)  On the same page I have 3 text boxes designated for telephone number. I would like the user to enter his/her area code in the first box, and after 3 digits are entered, I want it to jump to the next box for the the next 3 digits, then jump to the last box for the last four digits. I would then like the to have the phone number look like this (555) 123-1212, with parenthesis and dash once the Request.Form is done.

 





0
 
LVL 4

Expert Comment

by:dukestaTAI
ID: 11206916
Here you go:  Could you please submit points for this as well.  Thank you.

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
//  End -->
</script>
</HEAD>


<BODY>

<center>
<form>
<table>
<tr>
<td>Phone Number : <br>
1 - (
<small><input onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3"></small>) -
<small><input onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3"></small> -
<small><input onKeyUp="return autoTab(this, 4, event);" size="5" maxlength="4"></small>
</td>
</tr>
</table>
</form>
</center>
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now