Check Box Problem

Results 1 to 2 of 2

Thread: Check Box Problem

  1. #1
    Join Date
    Dec 1969

    Default Check Box Problem

    I have 10 check boxes in my asp page<BR>Name of checkboxes is same but value is different<BR>I want to make sure that user must check atleat on box<BR>what will be script for that<BR>I have write javascript for that but javascript only running <BR>when name of checkboex is different but when name of checkboxes same scripting not run<BR>Can some one help me <BR>i shall be very thankful<BR>

  2. #2
    Join Date
    Dec 1969

    Default When names of fields the same...

    ...JS automatically creates an *ARRAY* of the given name.<BR><BR>So if you have<BR><BR>&#060;INPUT Type="CheckBox" Name="Box" Value="1"&#062;<BR>&#060;INPUT Type="CheckBox" Name="Box" Value="2"&#062;<BR>&#060;INPUT Type="CheckBox" Name="Box" Value="3"&#062;<BR>&#060;INPUT Type="CheckBox" Name="Box" Value="Little Pigs"&#062;<BR><BR>Then you can see if one is checked this way:<BR><BR>&#060;SCRIPT&#062;<BR>function checkForOne( )<BR>{<BR>&nbsp; &nbsp; var boxes = document.FormName.Box;<BR>&nbsp; &nbsp; var count = 0;<BR>&nbsp; &nbsp; for ( var bnum = 0; bnum &#060; boxes.length; ++bnum )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; if ( boxes[ bnum ].checked ) ++count;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; if ( count == 0 ) <BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; alert("You must check at least one of the boxes!");<BR>&nbsp; &nbsp; &nbsp; &nbsp; return false;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; return true;<BR>}<BR>&#060;/SCRIPT&#062;<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