Link to home
Start Free TrialLog in
Avatar of Meps
MepsFlag for United States of America

asked on

Please help with validation

Here is what I want.  I have 4 groups of check boxes and text boxes, and when one group is selected it disables the remaining groups.

Here is my problem.  They are all dymanic from a cfloops.

Here is a example of what I am talking about
<CFSET rowcount = 1>
<CFLOOP QUERY="group 1">
<TR>
      <TD><INPUT TYPE="checkbox" NAME="check#rowcount#" VALUE=""></TD>
      <TD><INPUT TYPE="text" NAME="text#rowcount#"></TD>
</TR>
<CFSET rowcount =  rowcount + 1>
</CFLOOP>

<CFLOOP QUERY="group 2">
<TR>
      <TD><INPUT TYPE="checkbox" NAME="check#rowcount#" VALUE=""></TD>
      <TD><INPUT TYPE="text" NAME="text#rowcount#"></TD>
</TR>
<CFSET rowcount =  rowcount + 1>
</CFLOOP>

<CFLOOP QUERY="group 3">
<TR>
      <TD><INPUT TYPE="checkbox" NAME="check#rowcount#" VALUE=""></TD>
      <TD><INPUT TYPE="text" NAME="text#rowcount#"></TD>
</TR>
<CFSET rowcount =  rowcount + 1>
</CFLOOP>

<CFLOOP QUERY="group 4">
<TR>
      <TD><INPUT TYPE="checkbox" NAME="check#rowcount#" VALUE=""></TD>
      <TD><INPUT TYPE="text" NAME="text#rowcount#"></TD>
</TR>
<CFSET rowcount =  rowcount + 1>
</CFLOOP>

The names of the checkboxs are pretty much all the same except for their row number.  But I want to issolate one group and only that one group, and when someone clicks within the group I want to disable the the other groups.  Now here is when it gets ugly, I have no control over the rowcounts, like one day there will be 21 items in group 1, then the next day there could be 15, so the validation can't use any static numbers.

I know I just need to add a onclick to the group I wish to use, btw it is group 2.  But does anyone have any ideas?
ASKER CERTIFIED SOLUTION
Avatar of justinbillig
justinbillig

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of justinbillig
justinbillig

oh yeah and in each of your checkboxes put this


onclick="DisableGroups( this );"
also there is an extra } above the else statement, take it out
Avatar of Meps

ASKER

That works, but it also disables my submit buttons I have a "back", "reset", and "next" buttons.
Avatar of Meps

ASKER

I think I fixed the problem with the submit buttons, and had forgotten about a hidden field I needed enabled.

function DisableGroups( objTargetCheckBox ){
    // Variables
    var blnChecked = objTargetCheckBox.checked;
    var intIndex = 0;

    // Do we disable or enable?
    if( blnChecked == true ){
         // Disable
         for( intIndex = 0; intIndex < document.formName.elements.length; intIndex++ ){
              // Is this our checkbox?
              if( document.formName.elements[ intIndex ].name == objTargetCheckBox.name ){
                   // Yes, dont disable this or the next element ( the text box )
                   intIndex++;
              }
              else{
                    if( document.formName.elements[ intIndex ].name != "System_Record"){
                          if( document.formName.elements[ intIndex ].name != "GoBack"){
                              if( document.formName.elements[ intIndex ].name != "GoNext"){
                                    if( document.formName.elements[ intIndex ].name != "Reset"){
                   // No, disable
                   document.formName.elements[ intIndex ].disabled = true;
                                      }
                              }
                        }
                    }
              }
         }
    }
    else{
         // Enable, loop through all controls and enable them
         for( intIndex = 0; intIndex < document.formName.elements.length; intIndex++ ){
              // Enable this form element
              document.formName.elements[ intIndex ].disabled = false;
         }
    }
}
Avatar of Meps

ASKER

Thanks for your help.