I want to add JavaScript to my plugin php file, so that the 'checkout' button is only enabled when the user checks the terms and conditions checkbox.
I have found this solution in another user's question- but I'm having trouble implementing it to my php file in wordpress.
How do i disable a submit button when checkbox is uncheck?
I have created the checkbox and modified the button code in this function like you can see below:
function OutputContent_OnlineCheckoutButton()
{
echo '<input type="checkbox" id="checky"> I have read and agree to the <a href="#">terms and conditions</a>.<br/><input class="button-primary" id="postme" type="submit" disabled="disabled" name="'.$this->GetButtonID('checkout').'" value="'.__('Checkout', $this->myDomain).'"/>'."\n";
echo '<script language='JavaScript'>
$('#checky').click(function(){
$('#postme').attr("disabled",!this.checked);
});
</script>
'."\n";
}
But the javascript doesn't seem to be working, how should I implement the javascript to make it work?
Thanks in advance.
PS
This is the original code I had for the button on its own.
function OutputContent_OnlineCheckoutButton()
{
echo '<input class="button-primary" type="submit" name="'.$this->GetButtonID('checkout').'" value="'.__('Checkout', $this->myDomain).'"/>'."\n";
}