-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator2.html
executable file
·117 lines (74 loc) · 2.3 KB
/
calculator2.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<html>
<head>
<!-- Name- Payel Bandyopadhyay, Student Number - 014174692 -->
<script type='text/javascript'>
function cal1()
{
elem = document.getElementById('numbers');
var elemOne = elem.value;
elemOne = calculator(elemOne);
var check = elemOne.match(/-?[0-9]+\.?[0-9]*[+\-\/\*]-?[0-9]+\.?[0-9]*/);
while (check!= null)
{
elemOne = calculator(elemOne);
check = elemOne.match(/-?[0-9]+\.?[0-9]*[+\-\/\*]-?[0-9]+\.?[0-9]*/);
}
}
function calculator(e1)
{
var result;
var argument1;
var operator1;
var argument2;
var check;
result = e1.match(/-?[0-9]+\.?[0-9]*[+\-\/\*]-?[0-9]+\.?[0-9]*/);
if(result[0] !== null ) {
var res = result[0].match(/^\-/);
if(res !== null)
{
var res1 = result[0].substring(1, result[0].length);
}
else
{
res1 = result[0];
}
argument1 = result[0].match(/^-?[0-9]+\.?[0-9]*/);
operator1 = res1.match(/[^0-9\.]/);
argument2 = res1.match(/[+\-\*\/]([\-?0-9]+\.?[0-9]*)/);
argument2[0] = argument2[0].substring(1, argument2[0].length);
var p1 = ajaxFunction(argument1[0],operator1[0],argument2[0],e1);
e1 = p1;
}
return e1;
}
function ajaxFunction(arg1,op,arg2,element)
{
var xmlhttp= new XMLHttpRequest();
xmlhttp.open("GET","calc.php?arg1="+arg1+"&arg2="+arg2+"&op="+op,false);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState===4 && xmlhttp.status===200)
{
var newDiv = document.createElement("div");
newDiv.innerHTML = xmlhttp.responseText;
var nextElement = document.getElementById("numbers");
parentnode = nextElement.parentNode;
parentnode.insertBefore(newDiv, nextElement);
}
}
xmlhttp.send();
var response1 = xmlhttp.responseText;
var n = response1.indexOf("=");
response1 = response1.substring(n + 1, response1.length );
var rep = element.replace(arg1+op+arg2, response1);
return rep;
}
</script>
</head>
<body>
<form>
</br> <input type='text' id='numbers'/>
<input type='button' onclick="cal1()" value='Submit' />
</form>
</body>
</html>