How do I activate a button when click on a checkbox?
-
I have modified the bbpress form-topic.php file (in my child theme) to include a checkbox next to the submit button (for posting a new topic). This is to allow users to accept T&C’s before posting something. Therefore what I would like is to only enable the submit button when the checkbox is ticked.
I created a functions.php in my child theme.
`<?php
function apply_submit() {
?><script type=”text/javascript”>
document.frm.bbp_topic_submit.disabled=true;
if(document.frm.chk.checked==true) {
document.frm.bbp_topic_submit.disabled=false;
}
if(document.frm.chk.checked==false) {
document.frm.bbp_topic_submit.enabled=false;
}
</script><?php }?>`In form-topic.php I have:
<div class="bbp-submit-wrapper"> <form name="frm"> <input type="checkbox" name="chk" onClick="apply_submit()">Tick to accept <button type="submit" disabled tabindex="<?php bbp_tab_index(); ?>" id="bbp_topic_submit" name="bbp_topic_submit" class="button submit"><?php _e( 'Submit', 'bbpress' ); ?></button> </form>
The outcome of this is that the checkbox and submit button exist, but the button remains disabled even if I tick the checkbox. Therefore I don’t think it is finding the function.
I put some alerts in the function but none of these appeared when I check the box.Do you know what I could be missing?
Thanks
- The topic ‘How do I activate a button when click on a checkbox?’ is closed to new replies.