Click to See Complete Forum and Search --> : code for a form


dbmelosi
03-18-2003, 11:12 PM
Hello,
I am very new and a rookie to Javascript and am asking for a little help with code in a form.

I have 10 fields in a worksheet on an internal website.

field 1 enter a number
field 2 enter a number
field 3 enter a number
field 4 add fields 1 + 2 + 3
field 5 enter a number
field 6 enter a number
field 7 enter a number
field 8 subtract field 7 from field 6
field 9 (add field 4 + field 6) multiply the total times .12 then subtract 300 from the total
field 10 add field 4 plus field 5 plus field 8 plus field 9

I want to be able to calculate this and stay on the same page to use as a worksheet and be able to change the fields where you can enter a number.

I am sure that this is very simple....I am just struggling with it. I appreciate any help.
Thanks,
Dave

Nedals
03-19-2003, 12:35 AM
1. Your named fields must be enclosed within a named form... <form name="theform">
2. To get the value of a field use... val = document.theform.fieldname.value;
3. To put a value into a field use... document.theform.fieldname.value = val;
4. In javascript use * to multply... C = A * B;
5. Enclose all this in a javascript function
function calculate() {
.. the math ..
}
6. Add a button with.... onClick="calculate()"

That should give you enough information to solve this. If you get in trouble post the code you have developed and someone will help you out. If I do it all for you, you'll never learn.