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 6355085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:41:42+00:00 2026-05-24T22:41:42+00:00

$(document).ready( function (){ // bind the recalc function to the quantity fields $(input[name^=qty_item_]).bind(keyup, recalc);

  • 0
 $(document).ready(

    function (){


        // bind the recalc function to the quantity fields
        $("input[name^=qty_item_]").bind("keyup", recalc);
        // run the calculation function now
        recalc();


        // automatically update the "#totalSum" field every time
        // the values are changes via the keyup event

        $("input[name^=sum]").sum("keyup", "#totalSum");

        // automatically update the "#totalAvg" field every time
        // the values are changes via the keyup event
        $("input[name^=avg]").avg({
            bind:"keyup"
            , selector: "#totalAvg"
            // if an invalid character is found, change the background color
            , onParseError: function(){
                this.css("backgroundColor", "#cc0000")
            }
            // if the error has been cleared, reset the bgcolor
            , onParseClear: function (){
                this.css("backgroundColor", "");
            }
        });

    }

);

function recalc(){
    $("[id^=total_item]").calc(
        // the equation to use for the calculation
        "qty * price",
        // define the variables used in the equation, these can be a jQuery object
        {
            qty: $("input[name^=qty_item_]"),
            price: $("[id^=price_item_]")
        },
        // define the formatting callback, the results of the calculation are passed to this function
        function (s){
            // return the number as a dollar amount
            return "$" + s.toFixed(2);
        },
        // define the finish callback, this runs after the calculation has been complete
        function ($this){
            // sum the total of the $("[id^=total_item]") selector
            var sum = $this.sum();

            $("#grandTotal").text(
                // round the results to 2 digits
                "$" + sum.toFixed(2)
            );
        }
    );
}

</script>

<table width="500">
  <tr>
    <td align="center"><input type="text" name="qty_item_1" id="qty_item_1" value="1" size="2" /></td>
    <td align="center" id="price_item_1">$9.99</td>
    <td align="center" id="total_item_1">$9.99</td>
  </tr>
</table>

i am using the jquery calculation for the product and quantity , is there any way to make the quantity must less than 20, within the jquery and throughs validation error.ie: if the user enters the quantity >20 then it needs to show the jquery error otherwise it need to allow the user input.

  • 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-24T22:41:43+00:00Added an answer on May 24, 2026 at 10:41 pm

    You could use the jQuery validate plugin (http://docs.jquery.com/Plugins/validation) which is excellent for such scenarios.

    Wrap the table in a FORM with an ID, e.g.:

    <form id="items">
    ...your table markup
    </form>
    

    Initialise it like this:

    $(function () {
      $('#items').validate(
        rules: {
          'qty_item_1': { required: true, max: 20 }
        },
        messages: {
          'qty_item_1': 'Please enter a value less than 20'
        }
      );
    });
    

    Then, in your recalc function check that the form is valid, like so:

    function recalc(){

    if($('#items').valid()) {
      // the form is valid - continue
    
      $("[id^=total_item]").calc(
          // the equation to use for the calculation
          "qty * price",
          // define the variables used in the equation, these can be a jQuery object
          {
              qty: $("input[name^=qty_item_]"),
              price: $("[id^=price_item_]")
          },
          // define the formatting callback, the results of the calculation are passed to this function
          function (s){
              // return the number as a dollar amount
              return "$" + s.toFixed(2);
          },
          // define the finish callback, this runs after the calculation has been complete
          function ($this){
              // sum the total of the $("[id^=total_item]") selector
              var sum = $this.sum();
    
              $("#grandTotal").text(
                  // round the results to 2 digits
                  "$" + sum.toFixed(2)
              );
          }
      );
    
    } else {
      // the form is invalid - do nothing
    }
    

    }

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

Sidebar

Related Questions

$(document).ready(function() { $('form#search').bind(submit, function(e){ e.preventDefault(); $('#content').html(''); // Define the callback function function getGeo(jsonData) {
$(document).ready(function() { function countChecked() { var n = $(input:checked).length; $(div).text(n + (n <= 1
I have the following: $(document).ready(function(){ // bind 'myForm' and provide a simple callback function
I have the following code snippet: $(document).ready(function () { // bind 'regFormBody' and provide
I have a working script like this: jQuery(document).ready(function(){ $('.video-thumb img').bind('mouseover',function(){ var new = $(this).attr('src').replace(/default.jpg/,'1.jpg');
Can someone please help with converting this code to plain JS: $(document).ready(function() { $(textarea).bind(keydown,
il give an example document.ready(function() { $(#Show).bind(click, function() { var F = Function2(); if
Hallo, I've got something like this: $(document).ready(function(){ $(#all).height($(window).height()-60); $('a').bind({ mouseover:function(){ $(this).stop().animate({opacity:0.8},500); }, mouseout:function(){ $(this).stop().animate({opacity:1},500);
$(document).ready(function () { $('#eventTarget').bind(mouseover, changeColor);//This doesnt work $('#eventTarget').bind(mouseleave, changeColor);//This doesnt work $('#eventTarget').bind(click, function(){ //This
I have this jQuery script: <script type=text/javascript> $(document).ready(function{ $(#btnLogon).bind(click, function(){ $(#btnLogon).after('<span class=error>Please wait...</span>'); });

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.