This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
task10.html
79 lines (73 loc) · 2.04 KB
/
task10.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1></h1>
<form id="form_function">
<label for="function">Function</label>
<select name="function" id="function" required>
<option value="">--Select function--</option>
<option value="linear">Linear</option>
<option value="inverse">Inverse</option>
<option value="log">Log</option>
</select>
<br><br>
<label for="number">Number:</label>
<input type="number" id="number" required>
<br><br>
<input type="submit" value="Submit">
</form>
<h2>Result</h2>
<br>
<div id="result"></div>
<pre id="json"></pre>
<script>
window.onload=function()
{var form = document.getElementById("form_function");
form.addEventListener("submit", function(event)
{
event.preventDefault();
var sel=document.getElementById("function").value;
var num=parseFloat(document.getElementById("number").value);
if(sel==="inverse" && num==0)
{
alert("wrong input");
return;
}
if(sel==="log" && num<=0)
{
alert("wrong input");
return;
}
var res;
switch(sel)
{
case "linear":
res=num;
break;
case "inverse":
res=1/num;
break;
case "log":
res=Math.log10(num);
break;
default:
res="N/A";
}
document.getElementById("result").innerText = "Result: " + res;
var formdata={
"Selectedfunction":sel,
"InputNumber":num,
"Answer":res
};
document.getElementById("json").innerHTML=JSON.stringify(formdata,null,10);
});
};
</script>
</body>
</html>