hey all, long time no post.....
i have this script to work out the cost of loads of selected computer components, there are lots of drop down lists which each have a value which is the cost of that component.
firstly the script checks that the two main required fields are completed. this works fine.
then a for loop runs through the 15 elements on the form and is supposed to add together all the values of each selected component in the drop down lists. however i keep getting errors like "undefined42 is undefined." (42 happens to be the value of the first selected component, showing that it seems to work at least the first time through.
i'm using the eval function to evaluate the strings as a sum, is this right? - this is where i think the problem might be
ill leave you the code......
and a select box like:
thanks in advance
dd/mm/yy
i have this script to work out the cost of loads of selected computer components, there are lots of drop down lists which each have a value which is the cost of that component.
firstly the script checks that the two main required fields are completed. this works fine.
then a for loop runs through the 15 elements on the form and is supposed to add together all the values of each selected component in the drop down lists. however i keep getting errors like "undefined42 is undefined." (42 happens to be the value of the first selected component, showing that it seems to work at least the first time through.
i'm using the eval function to evaluate the strings as a sum, is this right? - this is where i think the problem might be
ill leave you the code......
Code:
<script language="JavaScript"> <!-- function quote() { var cost if (document.forms['components'].elements["case"].selectedIndex == 0) { alert('Please select a case.') return false } else if (document.forms['components'].elements["moth"].selectedIndex == 0) { alert('Please select a motherboard.') return false } for (i = 0; i < 16; i++) { cost = eval(cost + document.forms['components'].elements[i].value) } alert(cost) } //--> </script>
Code:
<select name="case"> <option value="0"></option> <option value="42">ENLIGHT / Desktop 230 Watt</option> <option value="135">ENLIGHT / Server Tower 400 Watt</option> <option value="29">STEK / Desktop 230 Watt</option> <option value="55">STEK / Large Tower 230 Watt</option> <option value="29">STEK / Midi Tower 230 Watt</option> </select>
dd/mm/yy
Comment