473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

adding a field value to a var causes a NaN in Explorer

var totalpoints=0;

for (counter=1;....){

myvalue=parseFloat(document.forms["myform"].elements[counter].value);
totalpoints+=myvalue

//the fields in elements[] are always numbers

}

In Internet Explorer the field numbers are not added while in Mozilla
everything works ok.

// I tried eval and parseint

Thanks

Oct 11 '05 #1
3 1892
kaston3 wrote:
var totalpoints=0;

for (counter=1;....){

myvalue=parseFloat(document.forms["myform"].elements[counter].value);
totalpoints+=myvalue

//the fields in elements[] are always numbers

}

In Internet Explorer the field numbers are not added while in Mozilla
everything works ok.


Try some troubleshooting
myvalue=parseFloat(document.forms["myform"].elements[counter].value,10);
if(isNaN(myvalue)){alert(myvalue+" is not a number");continue;}
if(!myvalue)){alert("Empty");continue;}

totalpoints+=myvalue

Mick

Oct 11 '05 #2
Lee
kaston3 said:

var totalpoints=0;

for (counter=1;....){

myvalue=parseFloat(document.forms["myform"].elements[counter].value);
totalpoints+=myvalue

//the fields in elements[] are always numbers

}

In Internet Explorer the field numbers are not added while in Mozilla
everything works ok.


Are you sure everything works ok in Mozilla? Is the value of the
first form element included? I'm thinking that the rest of the
line that you replaced with "...." may be important to identifying
your problem.

Since you're taking the extra step of storing the field value in
a temporary variable, adding:
alert("counter="+counter+"\myvalue="+myvalue);
should be one of the very first steps in debugging this problem.

Oct 11 '05 #3
JRS: In article <vs*******************@twister.nyroc.rr.com>, dated
Tue, 11 Oct 2005 15:00:43, seen in news:comp.lang.javascript, Mick White
<mw***********@rochester.rr.com> posted :

myvalue=parseFloat(document.forms["myform"].elements[counter].value,10);


,10 // ???

IMHO, parseFloat should only be used if the number part of the string
may have training characters; and parseInt only then or if the second
parameter may not be 10. Unless I've forgotten something.

Generally, when reading a number, one should IMHO do something like
myvalue = +document.forms["myform"].elements[counter].value
as it gets the conversion from "outer" to "inner" format out of the way,
and enables the inner value to be checked with a quick alert(myvalue) .

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
2
by: Simon Wigzell | last post by:
Is it possible within javascript to stop the little pulldown menu (with the values that the browser remembers have previously been entered into the field) from appearing? I have one very dense form...
2
by: alex bazan | last post by:
I'm building a cross-browser XML dataisland. This code works perfectly in mozilla, but i have problems with explorer. it tells me that: "diXML.getElementsByTagName(..).0 is null or not an...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
0
by: Andrew | last post by:
If item is a ListViewItem and str is a string, why do the following two lines not have the same effect ? item.SubItems.Add(new ListViewItem.ListViewSubItem()).Text = str;...
1
by: Andrew Robinson | last post by:
Give the following, is it possible to set a breakpoint in C# that fires when the value of x changes. I want to see the line that is changing the field x. Optionally, is it possible to fire a...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
7
by: turtle | last post by:
I want to find out the max value of a field on a report if the field is not hidden. I have formatting on the report and if the field doesn't meet a certain criteria then it is hidden. I want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.