Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2004, 12:53 AM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default Retrieving Dynamic Field Names

Hi Everyone,

I have created a dynamic check boxes where they can select muliple/ specific categories (stored on a db). I now need to retrieve the ones which they ticked. I have set the field id as the CategoryID and now need to retrive the field names that have been ticked. I relise i will need a For Loop, but how do i grab the FieldNames from the form that have been ticked.


Thanks Tim

*** Form Code ***
<input name="<%= objRSProject("ProjectID") %>" type="checkbox" id="<%= objRSProject("ProjectID") %>" value="yes">



TDA
__________________
TDA
 
Old January 12th, 2004, 01:37 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Tim,
Yes you are right you need to loop through the forms collection and look for checked boxes, then their name will be available to you.
However the to to this efficiently you need to be able to destinguish what a checkboxes name might have in it and test to see if it is a check box first. So i tend to name my dynamic fields with a prefix like.
*** Form Code ***
<input name="chk_<%= objRSProject("ProjectID") %>" type="checkbox" id="chk_<%= objRSProject("ProjectID") %>" value="yes">

So when I loop though the form I can pull out the checkboxes test the values and cut the name up to get the original "ProjectID"



Code:
for each obj in request.form
if left request(obj,4) = "chk_" then 'we have a checkbox
 ProjectID = right(obj,len(obj)-4)
 chkBoxValue = request(obj)
 'Do stuff with the values
end if
loop
Hope this helps a bit

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old January 12th, 2004, 01:56 AM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

Thanks Rod,

Thats exactly what i was after and also thanks for showing how to filter out other variables that may also contain Numeric values.

Tim :D


TDA
 
Old January 12th, 2004, 02:06 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

No worries

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old January 12th, 2004, 11:10 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Why not just use the value attribute of the checkbox? Only the checked checkboxes will be posted when the form is submitted. So you can create every checkbox with the same name/id, and simplify your loop by only checking that form field's value. Each checked checkbox's value will be separated by a ",".

<input name="chkChoosenField" type="checkbox" id="chkChoosenField" value="<%= objRSProject("ProjectID") %>">
...
aryFields = Split(Request("chkChoosenField"), ",")
For Each sField In aryFields
    'Do stuff here
Next

Peter
------------------------------------------------------
Work smarter, not harder.




Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT For Each - Field Names lahatfield XSLT 6 May 15th, 2007 06:33 AM
dynamic variable/object names TheBFJ Excel VBA 2 November 13th, 2006 07:11 AM
Get Field Names fizzerchris Classic ASP Databases 1 February 25th, 2006 05:06 AM
Retrieving Field Names RayRedSox Classic ASP Basics 0 October 12th, 2005 02:16 PM
retrieving value from dynamic checkbox navyanthgn Classic ASP Basics 1 May 19th, 2005 06:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.