I want to disable/enable a submit button if a checkbox is unchecked/checked, but the status of the button doesn't change.
I found a solution here:How do i disable a submit button when checkbox is uncheck?
Checkbox:
<h:selectBooleanCheckbox id="termsOfUseCheckbox" name="Sign Up" class="input-xlarge"/>
Submitbutton:
<p:commandButton type="submit" id="submitButton" action="#{genPlaceUserService.persist()}" value="Sign up" styleClass="btn btn-primary btn-large" disabled="true"></p:commandButton>
Javascript:
<script type='text/javascript'>
$('#termsOfUseCheckbox').click(function(){
if($(this).attr('checked') == true){
$('#submitButton').removeAttr('disabled');
}
else {
$('#submitButton').attr("disabled","true");
}
});
I know that primefaces needs the state of disabled (disable=true), that should be done by:
$('#submitButton').attr("disabled","true");
grateful for any help, kind regards!