asherinho Posted December 15, 2009 Share Posted December 15, 2009 I have a form with multiple select fields and text fields.Each select field is associated with a text field,the options of select fields carries the product name,id and unit saling price while the text fields takes the corresponding quantity.Here is my form <form id="form1" name="form1" method="post" action="sale.php"> <select name="product_name1"> <option value="">Select...</option> <option value="1" unit="3000">Cocacola</option> <option value="2" unit="4000">Pepsi</option> </select> <select name="product_name2"> <option value="">Select...</option> <option value="1" unit="3000">Cocacola</option> <option value="2" unit="4000">Pepsi</option> </select> <input type="text" name="quantity1" size="20"> <input type="text" name="quantity2" size="20"> <input type="text" name="total_price" /> <input type="button" value="Calculate" onclick="cal()" /> <input type="submit" value="submit"> </form> I want to calculate the total price by multiplying the unit sale price and quantity of each product then suming all of them,by using a javascript function call(),but it doesn't work.Below is the function <script language="javascript"> function cal(){ var count= 3; var i=1; var total=0; while(i<=count){ var num1=document.form1.product_name+i+.options.selectedIndex; var pick1=document.form1.product_name+i+.selectedIndex; var total2=document.form1.product_name+i+.options(pick1).unit*document.form1.quantity_sold+i+.value; i=i+1; total=total+total2; } document.form1.total_price.value=total; </script> What is wrong with the code above? Link to comment https://forums.phpfreaks.com/topic/185231-whats-wrong-here-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.