Here is my query. I am designing UI (in JSF) for license agreement page where "next" button will be enabled or disabled based on user's choice for accepting or denying the license agreement. Accept and decline buttons are radio buttons. I am using jquery for that. Here is jquery snippet:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
$('#pg2\\:accept').click(function() {
alert("hello");
if ($(this).is(':checked'))
$('#next').removeAttr('disabled');
else
$('#next').attr('disabled', 'disabled');
});
}
</script>
Here is my JSF code:
<h:panelgroup id="pg2">
<h:selectOneRadio id="radios" layout="pageDirection">
<f:selectItem id="accept" itemValue="#{true}" itemLabel=ACCEPT/>
<f:selectItem id="decline" itemValue="#{false}" itemLabel=DECLINE/>
</h:selectOneRadio>
</h:panelGroup>
<h:commandButton id="next" action="welcome" value="Next" widgetVar="nxt" />
Edit: replaced primefaces components with Jsf components as I cant use primefaces in my code
<p:commandButton>has its owndisabledattribute which you can set based on a condition. There should not be a need to fiddle around with extra JavaScript/jQuery code. (In this case, theidmay have been prepended unless you setprependIdof<h:form>tofalsewhich in turn, is nasty and should always be left untouched (totrueas default). It is not simplynext. Looking into the rendered HTML would help obtain the correctidcorresponding to the button).<h:commandButton>s. An<h:commandButton>also has adisabledattribute that requires a boolean value which you can set conditionally. If you disable a component only on the client-side using JavaScript/jQuery, its server-side state will nevertheless remain active and be exploitable.