Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maximum of 3 checkboxes only

Status
Not open for further replies.

jacksonbilly

IS-IT--Management
Mar 10, 2003
8
0
0
US
I am hoping I can get some assistance on a form I am creating. I have a set of 6 checkboxes on a form. They are all pertaining to the same question. The question requires the user to only check three boxes - none under or over - just three. Is there a way to validate this?

Thanks in advanced,

George

ps: the checkboxes are listed below and the URL the form is at is:
Value
BestPerformance
HighQuality
Convenience
Price
DontKnow
 
Code:
var chkNames = new Array("Value", "BestPerformance", "HighQuality", "Convenience", "Price", "DontKnow");

function checkBoxes(f)
{
  var count = 0;
  for (var i=0; i<chkNames.length; i++)
  {
    if (f.elements[chkNames[i]].checked)
      count++;
    if (count > 3)
      return false;
  }
  return (count == 3);
}
Pass the form containing the check boxes to the function.

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top