View Full Version : need a little help with my loop

07-17-2004, 04:09 PM
hey ppl,
i mtrying to implement a java scrip as a function which basically gets two numbers from the screen and multiplies them and then places the new
number onto another field. :D

but the ticky thing for me is the fact that the fields that the numbers come from are variable variables eg: product1, product2, product 3 (in a loop where i is incremented <input name='product$i' value='$product>.'

now im trying to do a similar thing is javascript and the code i have come up with is:

function do_math() {
var B = 1
Var num= A;
while (B < num) {
var quantity = eval(document.step5.quantity[B].value)
var price = eval(document.step5.price[B].value)
var calprice = quantity * price
document.step5.cal[B].value= calprice;

can anyone help me & btw is this question really really stoopid? :confused:

07-17-2004, 04:21 PM
function do_math() {
Var num= A;
for(var B = 1; B < num; B++) {
var quantity = new Number(document.step5['quantity' +B].value);
var price = new Number(document.step5['price' +B].value);
var calprice = quantity * price
document.step5.['cal' +B].value= calprice;
}This should work if you have A assigned a value before.


07-17-2004, 04:30 PM
A is a value that ive passed on from the page before.
does that make any problems, should it be $A instead. ne way the code provided above didnt work.
Thanx for the help though.
im still open to any suggestions

07-17-2004, 04:42 PM
I've edited it. If it still doesn't work post a sample source code of your page.


07-17-2004, 05:04 PM
thanx for the reply raf, il try it out and post the results asap.

Willy Duitt
07-17-2004, 06:21 PM
ne way the code provided ...

Please post the results in english so that we can read your reply....

Roy Sinclair
07-19-2004, 09:19 PM
Willy Duitt's request may seem a little rude at first glance but I want to assure you it's not. A lot of the people who both look for help here and who provide help here do not necessarily know english as their first language so they've already got an extra barrier to understanding in their way. When you start using slang expressions and simplified spelling it makes it even harder for those people. Since as I stated some of them are providing help, you may be foreclosing some of the help you can receive by making yourself unintelligable.

So help yourself by avoiding the the "instant messaging" style abbreviations and "cute" spellings.

07-20-2004, 10:35 AM
Thabks for the insight Roy and i totally understand what your trying to say.
Its going to be hard but im going to try and be as textbook as i can from now on. thanks for all the help anyway, youve all been a great help.