Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 11th, 2004, 11:53 PM
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
Reply With Quote
  #2 (permalink)  
Old January 12th, 2004, 12: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.
======================================
Reply With Quote
  #3 (permalink)  
Old January 12th, 2004, 12: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
Reply With Quote
  #4 (permalink)  
Old January 12th, 2004, 01: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.
======================================
Reply With Quote
  #5 (permalink)  
Old January 12th, 2004, 10: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,413
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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:11 AM
Get Field Names fizzerchris Classic ASP Databases 1 February 25th, 2006 04: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



All times are GMT -4. The time now is 02:48 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.