[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Please help with validation

Posted on 2004-11-09
6
Medium Priority
?
540 Views
Last Modified: 2008-03-06
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?
0
Comment
Question by:Meps
  • 3
  • 3
6 Comments
 
LVL 15

Accepted Solution

by:
justinbillig earned 300 total points
ID: 12532732
this is pretty easy,


do something like this

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
                  {
                        // 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;
            }
      }
}
            




replace formname with the name of your form
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12532737
oh yeah and in each of your checkboxes put this


onclick="DisableGroups( this );"
0
 
LVL 15

Expert Comment

by:justinbillig
ID: 12532743
also there is an extra } above the else statement, take it out
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Meps
ID: 12533012
That works, but it also disables my submit buttons I have a "back", "reset", and "next" buttons.
0
 
LVL 3

Author Comment

by:Meps
ID: 12533174
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;
         }
    }
}
0
 
LVL 3

Author Comment

by:Meps
ID: 12533182
Thanks for your help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question