Click here to Skip to main content
16,016,962 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript
<script>
var f, quantity, rate, customertotal, salertotal, totalshare;
function calc (f)
{
    quantity=parseInt(f.quantity.value);
    rate=parseInt(f.rate.value);
    customertotal=(quantity*rate);
    salertotal=(customertotal*.80);
    totalshare=(customertotal*.20);
    f.customertotal.value=customertotal;
    f.salertotal.value=salertotal;
    f.totalshare.value=totalshare;
}
</script>
Posted
v2
Comments
Can you provide the full code ?
I mean from where calc (f) function gets called ?
What is the value passed as f ?
niharcs063 4-May-13 1:32am    
This is the code where I want to add the calculation


<form action="insert.php" name="new_tran_form" method="post">
Coustomer Name :

<input name="customer_name" type="text" size="35">

<p>Saler Name :
       

<input name="saler_name" type="text" size="35" />

</p>
<p>FISH DETAILS</p>
<p>Type of Fish :


<input type="text" name="type_of_fish">

</p>
<p>Quantity :
     

<input type="text" id="quantity" name="quantity">

Kg</p>
<p>Rate :
           


<input type="text" name="rate">

Per Kg
</p>
<p>Mode of Payment :

<select name="mode_of_payment">
<option value="Cash">Cash </option>
<option value="Credit">Credit </option>
</select>

</p>
<input name="Calculation" type="button" value="Calculation" önclick="calc(f)"/>
<p align="right">

<input type="submit">
<input type="reset">
</p>
</form>
<input name="Calculation" type="button" value="Calculation" önclick="calc(f)"/>

What is "f" here ? What are you passing in "f" ?
Sergey Alexandrovich Kryukov 4-May-13 1:30am    
It can be wrong or correct only if you tell us what do you want to achieve.
—SA
Mohibur Rashid 4-May-13 10:19am    
If I got it right, then you have got it wrong. What is the initial value of f? probably nothing.

you wrote the code as

<script>

function calc ()
{
quantity=parseInt(document.getelementbyId("quantity").value);
rate=parseInt(f.rate.value);//fix it like above;
customertotal=(quantity*rate);//fix it like above;
salertotal=(customertotal*.80);//fix it like above;
totalshare=(customertotal*.20);//fix it like above;
document.getElementById("customertotal").value=customertotal;
document.getElementById("salertotal").value=salertotal;
document.getElementById("totalshare").value=totalshare;
}
</script>

you also have to create hidden object of totalshare and salertotal

1 solution

Please see my comment to the question. It does not really make sense.

However, there is at least one wrong thing, no matter what you wanted to achieve: the very first line. You should not declare anything outside of the function.

(Also, all brackets immediately following '=' are totally redundant, but this is not a bug.)

What I would advise? Maybe, try to get some basic knowledge about programming, not specifically JavaScript, read about programming a bit. Right now, it looks like you have no clue.

—SA
 
Share this answer
 
Comments
niharcs063 4-May-13 1:42am    
Please suggest what i am suppose to do now ???
Sergey Alexandrovich Kryukov 4-May-13 21:32pm    
Learn some basics of programming, to start from.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900