Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 988
  • Last Modified:

Managing unchecked checkboxes in array after post

Please pardon any misusage of terms if any. That being said here is my dilemma.
Within a basic form I have an array of 15 checkboxes all named "appliances" of which none, any or all can be checked. On submit my handling page properly post all the needed data to the DB just fine. However at the end of this page script I am sending to emails out vial SMTP send using the data values from the posting form before closing the connection to the DB.
I can collect everything without issue except for the checkbox values without causing an array out of range error. These I know are due to the unchecked box values being void. I have tried to use the "Request.Form("appliances")(1)" approach, which again works just fine if you check all the boxes.
Is there a way to provide a value of the uchecked box or a way to use the "Request.Form" method with a for loop around it so as to keep the array in range? I would rather not try to get the data from the DB if at all possable seice I have all the data in the posted form. Thank you!
0
hrj5721
Asked:
hrj5721
  • 10
  • 4
  • 3
  • +1
1 Solution
 
liorfrCommented:
can you post your HTML code here + the server side request snippet?
0
 
crshekharamCommented:
Try this code
for each ctl in Request.Form("appliances")
    Response.write (ctl)
next

Open in new window

0
 
hrj5721Author Commented:
Thank you crshekharam: This looks like it may wook, however I faild to mention this is within a emailbody string. I will provide a snippit of the html for referance. Thanks.
<td>Wall Oven: " & Request.Form("appliances")(1) & "</td><td>Steam Oven: " & Request.Form("appliances")(2) & "</td>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hrj5721Author Commented:
I have tried all ways that I know how to and I am not able to insert this for each operation into my string without receiving a syntax error at the " & for each function inside the string constant. I would like to make sure all understand that my goal place the value of each checkbox into its own cell for the sake of readability for the email recipient. Please let me know if I need to clarify anything.  Thanks.
0
 
crshekharamCommented:
As the checkboxes are static give a different name to each checkbox like
applicance1
applicance2

so that you can directly its value using request.form("appliance1"), request.form("appliance2")
0
 
hrj5721Author Commented:
Thank you for your sugestion crshekharam.
My origanal issue is based on the fact that there is no value posted when the checkbox has not been checked. This causes "array out of range" error. I like your "for each" solution but I need to figure out a way to get the output embeded ito my emailbody string. Thanks.
0
 
hrj5721Author Commented:
I am sorry, I need to let you know the reson all these checkboxes use the same name is because I am inserting this post into a DB as well as desplaying via user form for cliant at later time. :)
0
 
teebonProduct ManagerCommented:
Hi hrj5721,

You mentioned
"On submit my handling page properly post all the needed data to the DB just fine."

I would suggest you to re-retrieve the same data from the DB to populate your email message.
If you are having problem doing this, please attach your code portion where you "On submit my handling page properly post all the needed data to the DB just fine.", so that we may further assist you.


0
 
hrj5721Author Commented:
Thank you for your assessment teebon, I tried this but found I was having difficulty causing other issues. If you can drive me in the correct direction, that would be more than acceptable for sure. Page is attached.
insertintodb-Installation.txt
0
 
teebonProduct ManagerCommented:
Hi hrj5721,

I don't see why you could not reuse your variables strWall_Ovens, strSteam_Ovens ...

You could reuse them as follows:


"<br><br><form><table cellpadding='3' cellspacing='0' border='0' width='500'><tr><td>Wall Oven: " & strWall_Ovens & "</td><td>Steam Oven: " & strSteam_Ovens & ...

Open in new window

0
 
hrj5721Author Commented:
Thanks teebon, this does provide me with a true or false value, but I could have sworn I tried this at the start of this exercise without success. None-the-less, I believe what happened is after thinking I would not able to use these existing variables that it would be much more friendly to only write out the values I assigned from the checked checkboxes. At this point do you know of a way to accomplish this?

Also, in the meantime I have seen the "for each" loop provide a clean result with the values I have used for each type in the array only being displayed, now if I could only insert those values into the email string, it would offer up a choice. Thanks again for the follow through guys.
0
 
teebonProduct ManagerCommented:
Hi,

Can you clarify further what you meant by the following?
"write out the values I assigned from the checked checkboxes. "

A checkbox will either have the checked state or unchecked state.
If you do not want to display "true" or "false", you could add an if statement to write "yes" or "no" instead.
0
 
teebonProduct ManagerCommented:
Hi hrj5721,

Although still not fully understood how you populate your checkboxes, but I think by adding an extra set of variables might work for you:
strWall_Ovens = "false"
strSteam_Ovens = "false"

strWall_Ovens2 = ""
strSteam_Ovens2 = ""


    Dim iLoop
    For iLoop = LBound(aappliancesselected) to UBound(aappliancesselected)
       Select Case Trim(aappliancesselected(iLoop))

          Case "Wall_Ovens":

		strWall_Ovens = "true"
		strWall_Ovens2 = "Wall_Ovens"
		
          Case "Steam_Ovens":

		strSteam_Ovens = "true"
		strSteam_Ovens2 = "Steam_Ovens"

       End Select
    Next


...<table cellpadding='3' cellspacing='0' border='0' width='500'><tr><td>Wall Oven: " & strWall_Ovens2 & "</td><td>Steam Oven: " & strSteam_Ovens2  & ...

Open in new window

0
 
hrj5721Author Commented:
Good morning teebon, first let me clarify the statement below.
Can you clarify further what you meant by the following?
"write out the values I assigned from the checked checkboxes. " 

I have place a value of "Wall Ovens", "Steam Ovens" and so on& in the user form.
That being said your latest solution above looks clean and it makes sense now that I am able to use these variables as my source for data. I will implement and determine if this will solve my needs.
Thanks much.
0
 
crshekharamCommented:
Hi hrj5721
 Frankly speaking the code you have written can be simplified/efficient if you given different names to checkboxes.  You can eliminate lot of code and iterations.

Regards
Raj
strWall_Ovens=request.form("appliance1")
strSteam_Ovens=request.form("appliance2")

Open in new window

0
 
hrj5721Author Commented:
Thank you crshekharam for your sugestion. If I was not depending on the array based on the names being the same I would agree. If you know of a way I can collect the values (true or false) for my insert statement as well as a friendly value for the output, please let me know.
0
 
hrj5721Author Commented:
Hello teebon: Well it has taken me the better part of this day to completely understand how to use your most recent solution. It requires that the value of each checkbox be set to the name used for the matching case. Once I did this I can now get consistent values based on either case variable. I am only dealing with a rouge bug were as the last item in the array does not display a value at all. Must be a typo somewhere, None-the-less you win the points. Case Solved!
0
 
hrj5721Author Commented:
Willing to look for the solution based on the code being presented.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 10
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now