Jump to content

Whats wrong here? Help


asherinho

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.