File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Simple Addition Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Simple Addition" Watch "Simple Addition" New topic
Author

Simple Addition

Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi
there is no error in it but it produce addition like 1261 that instead of 10.

var j=0
var k=0
var total=0
for(i=0;i<4;i++)
{
x.form.elements[j+2].value=(x.form.elements[j].value)*(x.form.elements[j+1].value)
k=total+x.form[j+2].value//something wrong here
total=k
j=j+3
}
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1028
Hi Raja,
shouldn't x.form[j+2].value be x.form.elements[j+2].value ?
Check out also the function eval() e.g. eval( value + otherValue ) -- returns a number if mathematically interpretable.
There's also parseInt() and parseFloat().
ot: could it be, that my name in english and your name in your language have a fairly adequate meaning ? ...somehow
cb
[ May 15, 2003: Message edited by: Christian Baron ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
the 1621 is adding a tring together, use parsezInt(FormValue) to get it to a number
 
 
subject: Simple Addition
 
Threads others viewed
Can this Java code convert to Javascript code
need help with another loop
Increment Test
three for Loops?
loop
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture