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!
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.
^_^
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
^_^
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>
North America
Europe, Middle East and Africa
Asia Pacific