D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Some help with javascript & firefox

 



Steven Cote wrote:
have I done it wrong?

Yep, there's a couple mistakes in your version. I've actually taken the time to test my code this time, so this should definitely work. :)

You're reinitialising the value of sum in the for loop, so no actual addition will occur. Also, you're using a straight assignment, so the value from previous iterations is just getting overwritten. The "missing ; before statement error" was because you missed the single quotes around the word docuement and value, so it was trying to actually evaluate document.splitfm.vat_low (which doesn't actually exist). The last bit that we both missed was converting the evaluated sum from a string to an int. Oh yeah, and you missed the < sign in the for control, so you had an infinite loop. So, put all that together and you get a code block that looks like:

var sum = 0;
for( var i = 0; i <= rowNum; i++ ) {
   var vat_low = 'sum += parseint(document.splitfm.vat_low' + i + '.value)';
   eval(vat_low);
}


now I get
parseint is not defined
http://www.minionsbandb.co.uk/oldsplitaddtable.html
Line 106

what does the += mean after sum?

--

Regards: Kevin Lucas Post Master (Sub) Minions Shop & Tea Rooms Minions Liskeard Cornwall PL14 5LE www.minionsbandb.co.uk
-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html