Solved

VBScript Server Side Code to read checkbox.ID

Posted on 2009-05-14
2
310 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 500 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 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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 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