Check box validation!

Results 1 to 2 of 2

Thread: Check box validation!

  1. #1
    Join Date
    Dec 1969

    Default Check box validation!

    Hi, <BR>I am new to javascript. Can somebody help me please?<BR>I want user to select one check box only and display the message if they don&#039;t select anything or selects more than one. I know this has to be javascript. I wrote this code but nothing is displaying.<BR><BR>&#060;!--<BR>function checkit(){<BR> with (document.form1){<BR> var maxnumber= 1;<BR> for (var x=0; x&#060; number.length; x++){<BR> if((number[x].checked)&#062; maxnumber){<BR> window.alert("You can only select one number!");<BR> return false;<BR> }<BR> }<BR> return true;<BR> if (number[x].checked)== Null{<BR> alert("You have to select atleast one.");<BR> }<BR> return false;<BR> }<BR> }<BR> <BR><BR> //--&#062;&#060;/script&#062;<BR>&#060;FORM ACTION="find.asp" METHOD="post" id=form1 name=form1 onsubmit="checkit();"&#062;<BR><BR>Any help would be appreciated.<BR>Thanks.<BR><BR>

  2. #2
    aa Guest

    Default RE: Check box validation!

    Use another variable to count how many box has been checked.<BR><BR><BR>function checkit(){<BR>with (document.form1){<BR>var maxnumber= 1;<BR>var selectedSize = 0<BR><BR>for (var x=0; x&#060; number.length; x++){<BR>if(number[x].checked){<BR> selectedSize++;<BR>}<BR>}<BR><BR>if (selectedSize &#062; 1)<BR>{<BR> alert("You can only select one number!");<BR> return false;<BR>}<BR>if (selectedSize == 0){<BR> alert("You have to select atleast one.");<BR> return false;<BR>}<BR>return true;<BR><BR>}<BR>}<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts