|
|
 |
| 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.
|
 |

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

January 12th, 2004, 01:37 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: , , Australia.
Posts: 587
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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.
======================================
|

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

January 12th, 2004, 02:06 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: , , Australia.
Posts: 587
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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.
======================================
|

January 12th, 2004, 11:10 AM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |