2

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!

Community
  • 1
  • 1
user2314676
  • 21
  • 1
  • 2

2 Answers2

1

you could use this -> $(this).is(':checked') in place of $(this).attr('checked'), here's a jsfiddle -> http://jsfiddle.net/AfUGd/3/

edited the fiddle

  • thanks for your help! but the button still does not react on the status of the checkbox.. i know that xhtml needs disabled = "disbled", but i think primefaces needs disabled = "true". i tried both variants, but it doesn't work. – user2314676 Apr 24 '13 at 09:41
1

Actually what you need to do is not set disabled to true, but set disabled to disabled like this

$('#submitButton').attr("disabled","disabled");
pm.calabrese
  • 386
  • 6
  • 10