If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Validate checkboxes in a form - yaromat

Good morning. I am a complete newbie so if I am putting this in the wrong place please let me know. I am not a web developer. I have been asked to work on a web form at work and I am struggling through it.

I did the form in html.....that was not hard. Now I am doing validation on some of the fields with a javascript example that I got from a former co-worker. I am just tweaking it to make it work with my form. I have all the fields validated successfully except for the checkboxes. My current co-worker is going to take the info and send it in an e-mail using .asp. He told me to name all the checkbox fields the same thing to make his part easier. The problem is my validation method does not like duplicate names so this is not working. There are probably other ways to validate but I would like to stay with this method if possible since it works for all the other fields and since I am very green at this stuff.

Just because your colleague wants you to make his job easier does not mean you shouldn't write your HTML properly.
How about add an index to each check box such as:
<input type="checkbox" name="ActivityType0" value="Bank Secrecy Act/Structuring/Money Laundering">
<input type="checkbox" name="ActivityType1" value="Elder Financial Exploitation">

What if a user selected more than one box?

You can also use an array, if you really must use the same name for all checkbox fields.
<input type="checkbox" name="ActivityType[]" value="Bank Secrecy Act/Structuring/Money Laundering">
<input type="checkbox" name="ActivityType[]" value="Elder Financial Exploitation">

Notice, how I took out the blank space in the field's name.
It's a good habit to embrace because otherwise they are not valid JavaScript variables.

Do keep in mind when you are dealing with an array, then each element can be accessed through its index.
In your validation you need to loop through the array ActivityType to find out if at least one of the checkbox is ticked.