var i = 1;
var total = 0;
while (document.getElementById("single" + i) != null)
{
total += parseInt(document.getElementById("single" + i).value);
i += 1;
}Repeat as necessary. Or to be more sophisticated, make an array of your form object names so that you can loop through that and in each iteration run this while loop.
steve miller wrote:
Hi all.
Could use some help with javascript.
I am loading up a page with a variable number of columns depending on selections made on a previous screen. Each column contains identical textboxes which have identical names so php will deal with them as arrays (like singles[], parents[], children[], etc in this case) when submitted. When the page loads, I need to multiply a value from another textbox (that is not part of an array) by each of these boxes in a column, add the totals up, and enter the final value into yet another box. My problem is that I don't know how to reference the array boxes in javascript since they all have the same name. I need to do it in js so changes can be made and calcs done in the browser.
In other words, how do I tell javascript to use the boxes in col 1 for the first calc, then move on to the boxes in col 2 for the next calc...
There are also a gazillion other textboxes on the same page which are not used in the calc, so I don't think I can refernce them using form element numbers.
How do i do what I want to do?
steve
-- :::::::::::::::::::::::::::::: Howard Cheng http://www.howcheng.com/ Wise-cracking quote goes here.
____ � The WDVL Discussion List from WDVL.COM � ____ To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/ Send Your Posts To: [email protected] To change subscription settings, add a password or view the web interface: http://intm-dl.sparklist.com/read/?forum=wdvltalk
________________ http://www.wdvl.com _______________________
You are currently subscribed to wdvltalk as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED] To unsubscribe via postal mail, please contact us at: Jupitermedia Corp. Attn: Discussion List Management 475 Park Avenue South New York, NY 10016
Please include the email address which you have been contacted with.
