Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Value Any = Get Answer

if value is value<50 than deduct 5 into given value.
if value is value>50 than deduct 10% of given value into given value.

I want to get HTML/javascript Code for this calculation.
Thanx....
Posted
Updated 30-Sep-12 21:10pm
v4
Comments
Joan M 1-Oct-12 3:05am    
Add more detail to your question please... i.e.: where are those variables stored?

FIRST ANSWER
You can't do calculations using HTML as it is static, in order to do that you should use javascript or similar solutions.

Try it and come back if you face some problems.

SECOND ANSWER
In order to call a javascript code snippet you will have to create a form and react to the send button:
<form name='Myform' action='file_to_call.html' method='POST' enctype='application/x-www-form-urlencoded' onsubmit='return javascript_function();'>

Here you can see how to call a function before getting into the "file_to_call".

See forms and javascript in html to get more information and good samples on how to implement javascript calls in html.
 
Share this answer
 
v2
As we all know that Javascript is an event/action based client side scripting language. So on the action just call a javascript function which s'd contain the logic of your calculation.
 
Share this answer
 
This is basically it:

JavaScript
function calculate(value)
{
    var retVal;
    if(value <= 50)
        retVal = value - 5;
    else
        retVal = value * 0.95;
    return retVal;
}


Somewhere in your other javascript code:

JavaScript
var someValue = 50;
// other statements
// more statements
someValue = calculate(someValue);


Regards,

— Manfred
 
Share this answer
 
Comments
HNSuthar 1-Oct-12 5:14am    
<script>
function calculate();
{
var value=document.getElementsByName('value');
var ans=document.getElementsByName('ans');
if(??????????????????????????????
???????????????????????????????????????
??????????? Please, I want to know its Answer ????????????????????????????
??????????????????????????????????????)
}
</script>
<input type="number" name="value" önchange="function calculate()">
<input type="number" name="ans">

if customer put in value <50 then ans get = value-5
else ans get = value-10% (10% of value)

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