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!

0

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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

$('#submitButton').attr("disabled","disabled");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.