0

User check minimum one check box maximum four checkox javascript validation How ?

Edited by diafol: Don't post js questions in the php forum

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by ryantroop
0

a quick way I can think off the top of my head is to make an onchange function for the check boxes, that will take the particular check box being checked as a parameter. Each time it runs, it checks to see first if any boxes are checked. If not, recheck the box being unchecked, pop up an alert or whatever type of warning you would like to show.

If at least one is checked, we then count how many are checked. If more than 4, remove the new check and put up an alert.

You will most likely need a javascript for the submission part as well, to ensure security and consistency - as someone without javascript enabled could click away all day if you have a submit button that links to a CGI/PHP script without any checks on it, and defeat the purpose anyway.

Some of the language constructs you will need to read up on are:

onchange()

Loops or simple arithmetic with variables

You will also need to know about how to check for greater than or less than, and the alert() function if you wish to use it.

Remember, you can reuse the same function for each onchange if you make it right ;)

Good luck,

Ryan

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.