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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:59:02+00:00 2026-05-13T20:59:02+00:00

I added onkeyup javascript for a dynamically added textbox in javascript… But it doesnt

  • 0

I added onkeyup javascript for a dynamically added textbox in javascript… But it doesnt seem to work….

var cell4 = row.insertCell(3);
cell4.setAttribute('align','center')
var e3 = document.createElement('input');
e3.type = 'text';
e3.name = 'txtqt' + iteration;
e3.id = 'txtqt' + iteration;
e3.onkeyup = totalAmount(event,this,'tblsample');//Adding this lines doesnt work
e3.size = 10;
cell4.appendChild(e3); 

But when i used

e3.onkeyup = totalAmount;

It worked… Here is my javascript function,

function totalAmount(e,obj,tblid)
{

var tbl = document.getElementById(tblid);
//alert(tbl);
var tblRows = tbl.rows.length;
//alert(tblRows);
var result =0;

var str1;
if (obj != null) {
  str1 = obj.id;
} else {
  str1 = this.id;
}
var lastChar = str1.substring(5,str1.length);
//alert(lastChar);

if(str1=='txtqt'+lastChar)
{
    var str2 = 'txtup'+lastChar;
    var str3 = 'txtAmount'+lastChar;
    var txtDeduct = document.getElementById(str1).value;
    var txtAmt = document.getElementById(str2).value;
    var txtTotal = document.getElementById(str3);
    var totRes = txtAmt*txtDeduct;
    //var res = formatNumber(totRes,2)
    txtTotal.value = totRes.toFixed(2)
    document.getElementById('txttotAmount').value = totRes.toFixed(2);


    for(i=1;i<=tblRows;i++)
    {
    //alert(tblRows);
        txtTotID = 'txtAmount'+i;
        if(document.getElementById(txtTotID).value!='')
        {

            result =parseFloat(result) + parseFloat(document.getElementById(txtTotID).value);

            //var res= formatNumber(result,2)
            document.getElementById('txtTotalAmount').value = result.toFixed(2);
            document.getElementById('txttotAmount').value = result.toFixed(2);
            //document.getElementById('txtTotalAmount').value = result;
        }

    }

}

}

  • 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-13T20:59:03+00:00Added an answer on May 13, 2026 at 8:59 pm

    You need to wrap your function call in an anonymous function:

    e3.onkeyup = function(event){ totalAmount(event,this,'tblsample'); }
    

    But an even better way to do it, to allow for cross browser compatibility would be to use an addEvent function:

    function addEvent(obj,type,fn){
        if (obj.addEventListener){
            obj.addEventListener(type,fn,false);
        } else if(obj.attachEvent){
            obj["e"+type+fn]=fn;
            obj[type+fn]=function(){
                obj["e"+type+fn](window.event);
            };
            obj.attachEvent("on"+type,obj[type+fn]);
        };
    };
    

    And then add the event using that function:

    addEvent(e3,'keyup',function(event){ totalAmount(event,this,'tblsample'); });
    

    Just a much better way to handle events. I would recommend you switch to this method.

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

Sidebar

Related Questions

I added an event handler to the WebClient's DownloadProgressChanged event, but it never seems
Let's say I have this javascript: <script language=javascript type=text/javascript> function addtext() { var newtext
I added this code to the head but when I try to post something
i added this line.but it gives error.how to import it? import org.andengine.opengl.texture.atlas.TextureAtlas;
I added the following lines to Application_Start method in global.asax: var provider = new
Added: Working with SQL Server 2000 and 2005, so has to work on both.
The following javascript works with a simple test site i made, but does not
Added more details at the bottom of the question. We are testing deployment scenarios
I added to my system-wide /etc/security/limits.conf the following two rows: * soft rtprio 55
I added Jquery toggle/show hide in my site (click the plus sign) http://pligg.marsgibson.info if

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.