Forum Moderators: open
i was just reading a thread in the HTML & Browsers forum (http://www.webmasterworld.com/forum21/9610.htm) and it made me think of something i had come across over the last couple of days.
when i make forms, with checkboxes for instance, i have always, called them the name of the value i want and if the checkbox was not ticked, then request.form will not have them in. i also tend to prefix the elements so that i can easily distinguish them from each other..
so a simple
for each element in request.form
if substr(element,"chk") = 1 then
do stuff with the checkboxes
blah ..
end if
next
seems to do the trick..
however, one of my colleges, does something different..
he calls the checks the same thing(frmCheck), and gives them different values, and then.. does a
ids = request.form("frmCheck")
aIDs=Split(ids,",")
this to me seems alot better than a for each in loop
but is it bad skills? i am guessing it is, certainly if the elements have id= aswell as name=
just a thought.
thanks
nathan
Your code would be a benefit in that from a reusability standpoint, you could slap it into the page and never have to do anything else. That's only if you're doing the same thing to every checkbox in every page you use it in. If in your section where you say "do something with the checkboxes", you're writing custom code to process each different checkbox then I would not use this method. It's considerably less efficient to loop through every item in the request collection than it is to access them directly.
I do like that you're using naming conventions for your form elements. I've seen systems (like survey/questionaire/polling) that follow convention for naming all of their form inputs and can thereby use generic code to process any of them into the database that they're storing them in. ie: checkbox would be named "chk_<questionID>_<answerID>".
anyway, that's my thoughts.
-=casey=-