Ok, so, i have this code, that's suppose to be running using 'for' loop only. i know the code works, b/c when i do line by line manually, it works, but not when i do it in the loop, here's the code: var asdf = new Array('lb5a', 'lb10a', 'lb20a', 'lb30a', 'lb33a', 'lb40a', 'lb43a', 'lb50a', 'lb60a', 'lb100a', 'rva', 'motorFuela'); var cyl = new Array('lb5', 'lb10', 'lb20', 'lb30', 'lb33', 'lb40', 'lb43', 'lb50', 'lb60', 'lb100', 'rv', 'motorFuel'); var prices = new Array(11, 13, 15, 25, 22, 30, 32, 35, 45, 68, 2.75, 3.00); var formVar = new Array('cyl5', 'cyl10', 'cyl20', 'cyl30', 'cyl33', 'cyl40', 'cyl43', 'cyl50', 'cyl60', 'cyl100', 'rvs', 'motorFuel'); for(var i=0; i<asdf.length; i++) { // this is where i ALWAYS get the error, it says that this has not been // been initialized,,, help plz! this is driving me nuts asdf[i] = (document.frm.cyl[i].value * prices[i]); // display the prices document.frm.formVar[i].value = asdf[i]; } Code (markup):
Try this code, I think it will work var asdf = new Array('lb5a', 'lb10a', 'lb20a', 'lb30a', 'lb33a', 'lb40a', 'lb43a', 'lb50a', 'lb60a', 'lb100a', 'rva', 'motorFuela'); var cyl = new Array('lb5', 'lb10', 'lb20', 'lb30', 'lb33', 'lb40', 'lb43', 'lb50', 'lb60', 'lb100', 'rv', 'motorFuel'); var prices = new Array(11, 13, 15, 25, 22, 30, 32, 35, 45, 68, 2.75, 3.00); var formVar = new Array('cyl5', 'cyl10', 'cyl20', 'cyl30', 'cyl33', 'cyl40', 'cyl43', 'cyl50', 'cyl60', 'cyl100', 'rvs', 'motorFuel'); for(var i=0; i<asdf.length; i++) { // this is where i ALWAYS get the error, it says that this has not been // been initialized,,, help plz! this is driving me nuts asdf[i] = (document.frm[cyl[i]].value * prices[i]); // display the prices document.frm[formVar[i]].value = asdf[i]; } Code (JavaScript):
asdf = (document.frm.cyl.value * prices); << why are you using document.frm? try: asdf = (parseInt(cyl) * prices); I'm unsure of exactly what you are trying to do here. Can you provide the HTML code aswell.