Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everybody

I have the following javascript code that works fine in IE . But when i load this page in chrome the fields total get filled with NaN. Any help would be appreciated..

C#
 function Addvalue() {
        var gv = document.getElementById("<%=Grid_Insert.ClientID %>");
        var gvRowCount = gv.rows.length;
        var total = 0;
        for (i = 1; i < gvRowCount; i++) {
            for (j = 2; j < 15; j++) {
                var a = parseInt(gv.rows[i].cells[j].childNodes[0].value);
                if (j < 14) 
                {
                    if (!isNaN(a))
                     {
                        total = total + parseInt(gv.rows[i].cells[j].childNodes[0].value);
                     }
                }
                if (j == 14) {
                    gv.rows[i].cells[j].innerText = total;
                }
            }
        }
    }
the line 
if (!isNaN(a)) returns true when i Run my page in IE but Retrn false when I run in Chrome..

Pls Help
Posted
Updated 10-Oct-13 21:24pm
v2
Comments
thatraja 9-Oct-13 5:45am    
what's the error message? Check it in chrome debugger
ErBhati 9-Oct-13 5:56am    
when i load this page in chrome the fields total get filled with NaN

the value of total is NaN
thatraja 9-Oct-13 5:59am    
Try

if (!isNaN(parseInt(gv.rows[i].cells[j].childNodes[0].value))
{
total = total + parseInt(gv.rows[i].cells[j].childNodes[0].value);
}
ErBhati 9-Oct-13 6:10am    
It gives 0 each time
thatraja 9-Oct-13 7:13am    
Not clear, clarify

1 solution

Your test
if(value != NaN) 
is not the proper test.
Use:
if(!isNaN(value) )


REF: http://www.w3schools.com/jsref/jsref_isnan.asp[^]
 
Share this answer
 
Comments
Thomas Daniels 9-Oct-13 12:21pm    
Note: W3Schools shouldn't be treated as a reliable resource. See here why: http://www.w3fools.com/
W Balboos, GHB 9-Oct-13 13:21pm    
No doubt they've errors - and I've come across one now and then. (eg: DOM references not shown that, in fact, exist). The tutorials are a good jump-start for novices. Often there's a live test area for experimentation. Lots of neat reference table that are also quite reliable. Perfect? No.

But who are w3fools.com ? WhoIs shows there domain to be private. For a group that talks about openness and a Wiki form of W3Cschols - well - it's a bit of a "WTF?".

I 'fooled' with the isNan() to see how it works. Direct comparison to NaN didn't work .

Thomas Daniels 9-Oct-13 13:31pm    
W∴ Balboos wrote:
But who are w3fools.com?

Please see the "From" paragraph: there're a lot of Twitter accounts linked.
W∴ Balboos wrote:
The tutorials are a good jump-start for novices.

I disagree. On their PHP MySQL Insert Into page, the last example isn't protected against SQL Injection. I sent that as error several weeks ago, but it's still not updated :-(
W Balboos, GHB 9-Oct-13 13:49pm    
First of all - I don't "tweet' or use any of the other social networks - what's their problem with ownership of their domain? Rhetorical question.

As for your note about the .php tutorial - I stand by the idea 'jump-start' for a person to begin using php. There's lots of things it doesn't teach. But, I've a philosophy about that:

When someone gives me a doughnut I can either (1) thank them for the treat; or (2) complain there's a hole in it.

With respect to W3CSchools, I'm happy to enjoy the doughnut.
ErBhati 11-Oct-13 2:41am    
if(!isNaN(value) ) this condition false for evry no..

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