Hi guys, Lets consider if i were have 5 checkbox and a disabled submit button, how could i enable the submit button with at least one checkbox being ticked? Thank you in advance and have a nice day.
<script> var selected = 0; function EnableDisable(chk,sel) { var retVal = sel; if ( chk.checked ) { retVal++; } else { retVal--; } alert( chk.checked ); var o = document.getElementById("btnSubmit"); if ( retVal > 0 ) { o.disabled = ""; } else { o.disabled = "disabled"; } return retVal; } </script> <form id="frmTest"> <input id="chk1" type="checkbox" value="1" onclick="selected = EnableDisable(this,selected)" /> <input id="chk2" type="checkbox" value="1" onclick="selected = EnableDisable(this,selected)" /> <input id="chk3" type="checkbox" value="1" onclick="selected = EnableDisable(this,selected)" /> <input id="btnSubmit" type="submit" value="Submit" disabled="disabled"/> </form> HTML:
Hi! Remember the first thing you should consider when scripting in Javascript is how the page will behave if JS capability is not present. In this case, the user won't be able to submit the form, because you've disabled the submit button. I suggest you attach a load event listener, and disable the submit button through Javascript. That way, the JS and non-JS environments do not clash with each other. - P