?
Solved

VBScript Server Side Code to read checkbox.ID

Posted on 2009-05-14
2
Medium Priority
?
311 Views
Last Modified: 2012-06-27
I generate a dynamic set of checkboxes in Classsic ASP

<input type="checkbox" name="cbx1" id="cbx1" value = "abc" >
<input type="checkbox" name="cbx2" id="cbx2" value = "def" >
<input type="checkbox" name="cbx3" id="cbx3" value = "ghi" >

When the ASP Page is posted, I need to loop thru the checkboxes and read their ids in VBScript on the server.

For R = 1 to n
   set myCbx = request.form("cbx" & r)
   myID = myCbx.ID
Next

However the system doesn't like the myID = myCbx.ID line.  Is there any way to read the ID of a checkbox if it is not checked?

Thanks for your help
0
Comment
Question by:deepPowdah
[X]
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
2 Comments
 
LVL 8

Accepted Solution

by:
Bobaran98 earned 1500 total points
ID: 24391806
If the checkbox is not checked, then it does not get sent.  You can see this in the address line if you configure your form to be submitted with GET.  Assuming the first and third checkboxes are clicked, and your form action is set to submission.asp, you'll see this in your browser's address bar:

http://www.mydomain.com/submission.asp?cbx1=abc&cbx3=ghi

Note that cbx2 doesn't get passed at all.  Because it wasn't checked, it does not have a value as far as the submission is concerned.  The same goes if you submit your form via POST.

If you want to always send those three values, rather than making it dependent on the user checking/unchecking them, you could embed them as hidden values.  The user doesn't see the variables, but they still get submitted no matter what.  Example:

<input type="hidden" name="cbx1" id="cbx1" value = "abc" >
<input type="hidden" name="cbx2" id="cbx2" value = "def" >
<input type="hidden" name="cbx3" id="cbx3" value = "ghi" >
As for your loop, I'm not sure why you're processing it that way.  For one thing, you keep overwriting your variable.  For another thing, Request.Form("cbx" & r) is equal to the value tag and "cbx" & r is equal to the ID.  What more do you need to process?

Coming back to your question about knowing which checkboxes were NOT checked, you can certainly have your code determine that if you know what the values were to start with.  Try this... in your first page, the one with the checkboxes, add a hidden field called "cbxNum" and set the value to the number of checkboxes you've put on the page:

<input type="hidden" name="cbxNum" id="cbxNum" value = "3" >

Now when you process the submission, you can do this:

Dim cbxNum as integer
Dim myCbx as string
cbxNum = CInt(Request.Form("cbxNum")

For r = 1 to cbxNum
myCbx = Request.Form("cbx" & r)
If IsNull(myCbx) Or myCbx="" Then
Response.Write("cbx" & r & " was not submitted<br>\n")
Else
Response.Write("cbx" & r & " = " & myCbx & "<br>\n")
End If
Next
0
 

Author Closing Comment

by:deepPowdah
ID: 31581608
From what I have been able to determine, an unchecked checkbox does not have an ID or value property.  Only checked checkboxes have these properties.  The solution to my problem, as you suggested, was to create a hidden field in which I can put the vaue I need to keep.  I implementend that and it's sweet.  Thanks for your help.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 informatio…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

777 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