Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:00:57+00:00 2026-05-25T14:00:57+00:00

After a user enters some numbers and other data on a form a total

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:00:57+00:00Added an answer on May 25, 2026 at 2:00 pm

    Here is what I did. In my view I have the following code in one of my JavaScript methods. I use jQuery’s getJSON instead of ajax because it seemed to fit better (cleaner).

    $.getJSON(
      "/truckingmanagement/load/getTotal",
      {cargoSource:cargoSource, cargo:cargo, haulRate:haulRate, tonnage:tonnage, mileage:mileage, discount:discount, taxExempt:taxExempt},
      function(result) {
        if(result.message != null){
          alert(result.message);
          $("#discount").val("");
          $("#totalCell").html(result.total);
        }
        else{
          $("#totalCell").html(result.total);
        }
      });
    

    I my controller I still used the render method inside my closure, but modified it for JSON, making sure to import grails.converters.*.

    render(contentType:"text/json") {
        total = g.textField(name: 'total', value: totalBill, readonly: 'readonly')
        message = errorMessage
    }
    

    The totalBill value has been calculated prior to calling render, and errorMessage is 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 is null no message will be displayed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 'n' numbers in a TEXTAREA on a form. After the user enters
I want to clear the screen after user enters some numbers in C++. I'm
I have a form that performs calculations live as the user enters data. However,
I'm trying to update a p:datalist after user enters some informations to pop up.
In a Swing app a method should continue only after user enters a correct
My function below calls a partial view after a user enters a filter-by string
After a user adds 5 emails and their name to form below, and then
After a user submits a form, how do you detect that the form has
I have a form that and after the user fills in this form, I
I need to do some processing after my user leaves a text field. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.