Skip navigation
straffenp
Currently Being Moderated

Disable form/submit button

Mar 3, 2011 10:03 AM

Hi all,

 

I am outputting some records with form checkboxes so a user can delete multiple records at a time.  I'm trying to figure out a way to disable the submit button for the form until at least one checkbox is checked.  The name of each checkbox is unique using the record id.  Any help is greatly appreciated!  Thank you!

 
Replies
  • Currently Being Moderated
    Mar 4, 2011 12:47 PM   in reply to straffenp

    That's not a CF (server-side) function; that's a JavaScript (client-side) function, but I can show you.

     

    (It would be easier if all the checkboxes have the same name; this would create a "list" of ids that can be deleted, and would allow me to check against array length, but I'll see what I can do.)

     

    Give me a few moments.

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2011 1:00 PM   in reply to WolfShade

    This will work, as is, if there is only the ONE form on the page.  I think.. I haven't tested it.  You might need to tweak it.

     

    <script type="text/javascript">
    <!--
    function EDsubmit() {
         var inputArray = document.getElementsByTagName("input"); // gets all input elements - text, password, radio, checkbox, etc.
         var inputArrayLen = inputArray.length, totChecked = 0;
         for(i=0; i<inputArrayLen; i++) { // Loops through all INPUTs
              switch(inputArray[i].type) {
                   case "checkbox": // We are only concerned with CHECKBOX inputs
                        inputArray[i].checked == true ? totChecked++ : null ;
                   break;
                   default: // .. and ignore all others
                   break;
                   }
              }
              document.forms[0].submit.disabled = totChecked == 0 ? true : false ;
         }
    //-->
    </script>
    

     

    Set this to run on page load, and also apply it to each checkbox in the "onchange" event.

     

    LMK

     

    ^_^

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 7, 2011 3:27 AM   in reply to straffenp

    Here you go, experiment with this

     

    <form action="" method="get">

     

    <input name="a" type="checkbox" value=""  id="id" onclick="if(a.checked || a1.checked || a2.checked) b.disabled=false; else b.disabled=true; "/>
    <input name="a1" type="checkbox" value="" id="id1" onclick="if(a1.checked || a.checked || a2.checked) b.disabled=false; else b.disabled=true; "/>
    <input name="a2" type="checkbox" value="" id="id2" onclick="if(a2.checked || a.checked || a1.checked) b.disabled=false; else b.disabled=true; "/>
    <input name="b" type="button" disabled="true" value="button">

     

    </form>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points