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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:24:27+00:00 2026-06-12T00:24:27+00:00

I have a piece of code that creates check boxes in a table in

  • 0

I have a piece of code that creates check boxes in a table in a loop and calls their onclick function. In the onclick function, I try to populate a global array that will be a position holder for the checked check boxes of the table. Also if a row is checked, I have to sum the numbers in a text field of that row(I add this to a variable percentage) and if the variable crosses 100 I have to alert the user and ask him to enter values in the checkbox such that the sum is less than 100.

My problem is that each time I click a check box, the global array gets populated, sum is stored in the variable as expected, but the ‘tick’ on the check box doesn’t come/disappears immediately.

How do I solve this issue?

Code:

    {
var tabId=document.getElementById("AmnestyTransTbl"); 
var tabrows = tabId.getElementsByTagName('tr');

var percentage=0,c,n;
var ar=[];
for(var i=1,c=2;i<=tabrows.length-3;i++,c=c+2)
{
// Create CheckBox
ar[i]=c;
var checkBox = document.createElement("input");
checkBox.setAttribute("type", "checkbox");
checkBox.id='CB'.concat(i);
checkBox.onclick = function ()
{

var tabId1=document.getElementById("AmnestyTransTbl"); 
var rowInd=getRowIndex(this);

CBValue[rowInd]=this.checked;
 n=ar[rowInd-1];
 percentage=(parseInt(percentage) + parseInt(tabId1.getElementsByTagName("input")[n].value));
 if(parseInt(percentage)>100) 
 {
 alert("Amnesty Percentage,"+percentage+", greater than 0!. Plesase check again.");
 this.checked=false;
 }
 if(this.checked==false)
 percentage=parseInt(percentage)-parseInt(tabId1.getElementsByTagName("input")[n].value);
 }    }
var td = document.createElement("td");
td.appendChild(checkBox);
tabrows[i+1].cells[1].appendChild(td);
}

function getRowIndex(el)
{
while((el=el.parentNode) && el.nodeName.toLowerCase() != 'tr');
if (el)
return el.rowIndex;
}
  • 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-06-12T00:24:28+00:00Added an answer on June 12, 2026 at 12:24 am

    Got the culprit i guess,

    Plz try replacing this

     if(parseInt(percentage,10)>100) {
                  this.checked=false;
              }
    
              if(this.checked=false)
              {
                   percentage=parseInt(percentage)-parseInt(tabId1.getElementsByTagName("input")[n].value);
              }
    

    with this

    if(parseInt(percentage,10)>100) {
                  this.checked=false;
              }
              else
              {
                  this.checked=true;
              }
    
              if(this.checked==false)
              {
                   percentage=parseInt(percentage)-parseInt(tabId1.getElementsByTagName("input")[n].value);
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code that calls a WCF service that is hosted
I have a piece of code that creates an SQL Server Express 2008 in
Does anyone have a piece of JavaScript code that creates a cookie and stores
I have a piece of code that creates dynamic controls using 2 while loops.
I have a piece of code that was written by someone else before the
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated
I have a piece of code that load a very big image in memory.
I have a piece of code that takes several rows from a database and
I have a piece of code that look similar to this: <xsl:choose> <xsl:when test=some_test>

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.