p2p.wrox.com 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 12th, 2004, 12:53 AM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old January 12th, 2004, 01:37 AM
Friend of Wrox
Points: 2,244, Level: 19
Points: 2,244, Level: 19 Points: 2,244, Level: 19 Points: 2,244, Level: 19
Activity: 12%
Activity: 12% Activity: 12% Activity: 12%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 587
Thanks: 1
Thanked 1 Time in 1 Post
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.
======================================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old January 12th, 2004, 01:56 AM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old January 12th, 2004, 02:06 AM
Friend of Wrox
Points: 2,244, Level: 19
Points: 2,244, Level: 19 Points: 2,244, Level: 19 Points: 2,244, Level: 19
Activity: 12%
Activity: 12% Activity: 12% Activity: 12%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 587
Thanks: 1
Thanked 1 Time in 1 Post
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.
======================================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old January 12th, 2004, 11:10 AM
planoie's Avatar
Friend of Wrox
Points: 16,368, Level: 55
Points: 16,368, Level: 55 Points: 16,368, Level: 55 Points: 16,368, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT For Each - Field Names lahatfield XSLT 6 May 15th, 2007 07: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 03:16 PM
retrieving value from dynamic checkbox navyanthgn Classic ASP Basics 1 May 19th, 2005 07:16 PM



All times are GMT -4. The time now is 05:10 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc