QUOTE(Mytro @ May 6 2017, 01:39 AM)
Hello guys , i am new to using HTML , and i would like to create something that would allow a visitor on the website to input numbers and based on those numbers he would get a result .
That can be done with javascript or a server side script like PHP, which one to choose depends on how important the functionality is.
QUOTE
So bassicaly what i need is when a user inputs 40 , 1 , 2 he would get 10 * 40 * 1,15 * 3 = 1788.5 .
When I multiply
10 * 40 * 1,15 * 3 I get
1380 with my calculators, but 1379.9999999999998 with the below javascript in my browsers.
Maybe the decimals are due to javascript's loose treatmeant of numbers, not sure.
CODE
<script type="text/javascript">
function calculate()
{
var x_field=document.getElementById('x_field').value;
var y_field=document.getElementById('y_field').value;
var z_field=document.getElementById('z_field').value;
var x_const=8;
if(x_field<54)
{
x_const=10;
}
var y_const=1.35;
if(y_field==1)
{
y_const=1.15;
}
else if(y_field==2)
{
y_const=1.25;
}
var z_const=4;
if(z_field==1)
{
z_const=2;
}
else if(z_field==2)
{
z_const=3;
}
document.getElementById('result_field').value=x_field * x_const * y_const * z_const;
}
</script>
<input type="text" id="x_field" value="40">
<input type="text" id="y_field" value="1">
<input type="text" id="z_field" value="2">
<hr>
<input type="button" value="Calculate" onclick="calculate();">
<input type="text" id="result_field" value="">