user2504767
user2504767

Reputation:

How to assign a boolean value of an JSF selectBooleanCheckbox as parameter to a java script function?

I have the following example in my jsf xhtml page:

<h:selectBooleanCheckbox value="#{bean.fieldvalue1}" onchange="updateJsFunction(this);"/>

The parameter "this" for the js function "updateJsFunction" doesn´t includes the value of the selectBooleanCheckbox, which was selected or deselected.

Is there a way to assign the value of an selectBooleanCheckbox in a java script function?

Upvotes: 0

Views: 572

Answers (2)

Daniel
Daniel

Reputation: 37051

You can replace onchange="updateJsFunction(this);" with onchange="updateJsFunction(event);"

And then do what ever you want with $(event.target) (if you use jQuery) or inspect the event.target with js

Upvotes: 1

Christophe Roussy
Christophe Roussy

Reputation: 16999

Yes you have to work on the DOM. The 'this' you refer to is the generated HTML checkbox, you must see if it has the attribute 'checked'. If you use jQuery it would be something like:

jQuery(this).is(':checked')

Upvotes: 1

Related Questions