Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
get this error... "Uncaught TypeError: Cannot read property '0' of undefined"
on checkbox onclick event in asp.net on Chrome in consolelog, and debugger is not responding on the event . while its working perfectly on Internet explorer....plz help.. thanx in advance

my code for js is :
JavaScript
function calculation1() {
   var sum = 0.00;
   var itemsum = 0.00;

   var gridview = document.getElementById('<%=gvw_Search.ClientID %>');

   for (var row = 1; row < gridview.rows.length; row++) {
       var quantity = document.getElementById(gridview.rows[row].cells[2].all[0].id);
       var chkBox = document.getElementById(gridview.rows[row].cells[3].all[0].id);

       if (!isNaN(gridview.rows[row].cells[2].innerText)) {
          if (chkBox.checked) {
            sum = sum + parseFloat(gridview.rows[row].cells[2].innerText);
          }
       }
   }

   var totallbl = document.getElementById('<%=txt_Amount.ClientID %>');
   totallbl.innerText = sum.toString();
}


[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v4
Comments
Sunasara Imdadhusen 7-May-14 9:15am    
Can you please provide generated HTML here? it will give more idea about your HTML structure
Sanket Saxena 7-May-14 9:22am    
try putting an else condition in
if (chkBox.checked) {
sum = sum + parseFloat(gridview.rows[row].cells[2].innerText);
}
else
{
//do something
}

As index 0 mentioned in the exception message only appears in the expression all[0], you could make a conclusion that the property all was never defined for the cell object.

Some background, just in case:

Properties of a Javascript object and the result of indexing of the object by any other object is the same. All objects are associative containers, or associative array:
http://en.wikipedia.org/wiki/Javascript#Dynamic[^],
http://en.wikipedia.org/wiki/Associative_container[^].

Compare:
JavaScript
something = { someProperty:"some value", 3:"value @3" };
something.value = "some other value";
alert(something["someProperty"] + '\n' + something["value"] + '\n' + something[3]);

Will show the alert:
some value
some other value
value @3


—SA
 
Share this answer
 
v4
Solved.... The problem was innertext value insertion is not allowed in chrome and firefox... they use textContent to insert the text in object.... using a try catch condition ... i use both of the codes .... if it got any error than it will go to next code in the catch() section... Thanx guys for your advices
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900