Reputation: 640
When the user clicks on the checkbox, I want to call a controller function and pass the current status of checkbox, whether it's checked or not.
I know how to do this using jQuery but I want to do this from the checkBox itself.
<g:checkBox id="customer_checkbox" name="customer_checkbox" value="${checked}" />
Controller function to be called:
class updateController {
def updateIndex () {
// do something
}
}
Upvotes: 1
Views: 2025
Reputation: 1217
U need to use remoteFunction from grails taglib. This tag generate for u ajax function:
<select from="[1,2,3,4,5]" onchange="${remoteFunction(action: 'updateIndex', controller:'update',options: '[asynchronous: true]'}" />
For more information go to docs
Upvotes: 3
Reputation: 174
The checkbox would be a part of the form. Use javascript to invoke the action.
<g:form name="formName" controller="updateController" action="updateIndex">
<!-- Other form elements -->
<g:checkBox id="customer_checkbox" name="customer_checkbox" value="${checked}" onChange="document.getElementById('formName').submit();"/>
</g:form>
Upvotes: 1