After a user enters some numbers and other data on a form a total is calculated. The user might also choose to enter a discount amount. I use a jQuery AJAX method to send all the data to the getTotal method in the Load controller. If the user entered a discount amount greater than the calculated total I want a message box to pop up (similar to a JavaScript alert box) saying the discount must be less than the total. Is there any clean way to do this from the controller?
After a user enters some numbers and other data on a form a total
Share
Here is what I did. In my view I have the following code in one of my JavaScript methods. I use jQuery’s
getJSONinstead ofajaxbecause it seemed to fit better (cleaner).I my controller I still used the
rendermethod inside my closure, but modified it for JSON, making sure toimport grails.converters.*.The
totalBillvalue has been calculated prior to callingrender, anderrorMessageis just a string that contains a message based on what the error was (negative discount value or discount value greater than total) or no message at all. Thus if the message isnullno message will be displayed.