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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:03:22+00:00 2026-05-27T01:03:22+00:00

My Javascript function aa() is called with the value of the paying_now input field.

  • 0

My Javascript function aa() is called with the value of the paying_now input field. I want to find the sum of the value of paying_now and of paid, and the difference of balance and paying_now.

The values of netpay, balance, and paid will be fetched from a database. Here, I have set net_pay to 1000, as an example.

This code works only with balance and doesn’t change the paid textbox, when the paying_now value should be added to it. NaN is also occuring. What gives?

Javascript

   function aa(paying_now)
    {
        var net_pay = document.getElementById('net_pay').value;

        var paid = document.getElementById('paid_hidden').value;
        var balance = document.getElementById('balance_hidden').value;

        if(parseInt(paying_now) > parseInt(net_pay))
        {
            document.getElementById('paying_now').value=0;
            document.getElementById('paid').value=paid;
            document.getElementById('balance').value=balance;
            alert("Amount Paying now cannot be higher than Netpay");
            return;
        }
        else if(parseInt(paying_now) > parseInt(balance))
        {
            document.getElementById('paying_now').value=0;
            document.getElementById('paid').value=paid;
            document.getElementById('balance').value=balance;
            alert("Amount Paying now cannot be higher than balance amount");
            return;

        }

    document.getElementById('paid').value = parseInt(paid)+parseInt(paying_now);
    document.getElementById('balance').value = parseInt(balance)-parseInt(paying_now);

    }

HTML

<table> 
    <tr>
        <td>
            <strong>Netpay:</strong>
            <input type='text' id='net_pay' value = '1000' readonly />
        </td>
        <td>
            Paid: <input type='text' value='100' id='paid' name='paid' readonly />
            <input type='hidden' value='100' id='paid_hidden' ></td>
        </td>
        <td>
            <strong>Balance:</strong>
            <input type='text' value='900' id='balance' readonly />
            <input type='hidden' value='900' id='balance_hidden' />
        </td>

        <td>
            <strong>Paying now:</strong><input type='text' id='paying_now' onkeyUp='aa(this.value);' />
        </td>
    </tr>
</table>

For what it’s worth, here is a JSFiddle with this code: http://jsfiddle.net/JeSZX/

  • 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-27T01:03:22+00:00Added an answer on May 27, 2026 at 1:03 am

    I have modified the code. Please implement this, its working fine.

    function aa(paying_now)
    {
        var net_pay = document.getElementById('net_pay').value;
        var paid = document.getElementById('paid_hidden').value;
        var balance = document.getElementById('balance_hidden').value;
    
        if(paying_now === ""){
            document.getElementById('paid').value = paid;
            document.getElementById('balance').value = balance;
        }    
        else if(parseInt(paying_now) > parseInt(net_pay))
        {
            alert("Amount Paying now cannot be higher than Netpay");
            document.getElementById('paying_now').value="";
            document.getElementById('paid').value=paid;
            document.getElementById('balance').value=balance;
            document.getElementById('paying_now').focus();
        }
        else if(parseInt(paying_now) > parseInt(balance))
        {
            alert("Amount Paying now cannot be higher than balance amount");
            document.getElementById('paying_now').value="";
            document.getElementById('paying_now').focus();
        }
        else{
        document.getElementById('paid').value = parseInt(paid)+parseInt(paying_now);
        document.getElementById('balance').value = parseInt(balance)-parseInt(paying_now);
        }
    }
    

    There were some small mistakes in html code, please change that too. For example, in certain places closing tag were missing. Put the hidden field inside <td> and </td> only.

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

Sidebar

Related Questions

I have a javascript function being called by an input type=image tag that generates
I want to pass a Javascript variable as a argument of a function called
I have a Javascript function which should update a hidden input field in my
I have a Javascript function that is called from the onchange method in a
When I click on the hx:commandExButton the Javascript function should get called, but it
I have a javascript function that manipulates the DOM when it is called (adds
On the click of a button this Javascript is called: var xmlhttp; function register()
Why does the JavaScript function encodeURIComponent encode spaces to the hex Unicode value %20
I'm working on a javascript function that when called will make a ajax request
In my application, I have a Javascript function which get called after every minute.

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.