I'm using a g:select (actually, a g:currencySelect) in my view.
I want a controller action to fire as soon as the user changes the value in the resulting select box.
How can I do this?
I'm using a g:select (actually, a g:currencySelect) in my view.
I want a controller action to fire as soon as the user changes the value in the resulting select box.
How can I do this?
 
    
    I think I'm answering my own question here, but do let me know if there's a better way of doing this:
Use the onchange javascript function in the select tag:
<g:form controller="changeCurrency" action="changeCurrency">
    <g:select onchange="submit()"/>
</g:form>
 
    
    In case you want an ajax request, try this:
<g:select name="type" from="${['import-a', 'import-b']}"
onchange="jQuery('#addArea').load('/app/import/chooseImportType/' +
jQuery('#type').val())"/>
In controller:
def chooseImportType (){
 render params.id
}
Worked in Grails 2.0.4
 
    
    Another way can be:
    <g:select name="someName" from="${list}" onchange="goToPage(this.value)"/>
    <script type="text/javascript">
    function goToPage(requestParams){
    window.location.href="${createLink(controller:'controllerName' ,action:'actionName' ,params:[paramsName:""])}" + requestParams;
    }
    </script>
    