[thelist] Checkboxes and the ASP Form collection

Aaron Johnson ajlist at mindseye.com
Fri Feb 8 10:55:01 CST 2002


Hey Ben,

On Fri, 2002-02-08 at 11:39, Ben Gustafson wrote:
> I'm writing an ASP script to do dynamic server-side form validation. One
> of the steps is to request the Form collection and iterate through it to
> check the items. I'm having a problem with checkboxes and radio buttons,
> though. I've found that if they are not checked, they do not get into
> the Form collection. Text input elements do get into the collection if
> they are empty, as long as a value attribute, empty or otherwise, is in
> the Input tag. I could hard code the names of the checkbox form elements
> into the validation script and flag them as invalid if they're not in
> the collection, but that would defeat the purpose of making the
> validation script dynamic. Does anyone have a way around this?

One way to quickly get around it is to put a hidden field in your form
that has the same name as your checkboxes.  That way the field is sent
regardless of whether or not the user checked any radio buttons or
boxes..   This method starts to break down if you use Javascript to
modify those fields on the client side, but for the most part is pretty
durn effective.

HTH

AJ




More information about the thelist mailing list