add script for display result from server
This commit is contained in:
parent
d665bdbf5e
commit
fd5344a896
26
calc.html
26
calc.html
@ -3,15 +3,27 @@
|
||||
<head>
|
||||
<title>HTML / CSS</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
<script src="jquery-3.3.1.js"></script>
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<form method="GET" action="http://webex.sdi.hevs.ch/calc">
|
||||
<p>Operand 1</p>
|
||||
<input type="number" name="operandA"><br>
|
||||
<p>Operand 2</p>
|
||||
<input type="number" name="operandB"><br><br>
|
||||
<input type="submit" value="Calculate">
|
||||
<input type="reset"><br><br>
|
||||
<form method="GET" action="http://webex.sdi.hevs.ch/calc" class="inline-divs">
|
||||
<div id="op1">
|
||||
<p>Operand 1</p>
|
||||
<input type="number" name="operandA">
|
||||
</div>
|
||||
<div id="op2">
|
||||
<p>Operand 2</p>
|
||||
<input type="number" name="operandB">
|
||||
</div>
|
||||
<div id="but">
|
||||
<input type="submit" value="Calculate"> <br>
|
||||
<input type="reset">
|
||||
</div>
|
||||
<div id="res">
|
||||
<p>Result</p>
|
||||
<input type="text" name="result" readonly>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
10364
jquery-3.3.1.js
vendored
Normal file
10364
jquery-3.3.1.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
18
script.js
Normal file
18
script.js
Normal file
@ -0,0 +1,18 @@
|
||||
$(document).ready(function() {
|
||||
$('form').on('submit', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var operandA = $('input[name="operandA"]').val();
|
||||
var operandB = $('input[name="operandB"]').val();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'http://webex.sdi.hevs.ch/calc',
|
||||
data: { operandA: operandA, operandB: operandB },
|
||||
success: function(data) {
|
||||
var result = $(data).find('strong').text();
|
||||
$('input[name="result"]').val(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
31
styles.css
31
styles.css
@ -1,5 +1,28 @@
|
||||
body {
|
||||
div[id="op1"] {
|
||||
background-color: lightskyblue;
|
||||
margin: 5px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
div[id="op2"] {
|
||||
background-color: lightgreen;
|
||||
margin: 5px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
div[id="but"] {
|
||||
background-color: palevioletred;
|
||||
margin: 5px;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
div[id="res"] {
|
||||
background-color: yellow;
|
||||
margin: 5px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
input[type="number"] {
|
||||
@ -12,4 +35,10 @@ input[type="submit"] {
|
||||
|
||||
input[type="reset"] {
|
||||
background-color: palevioletred;
|
||||
}
|
||||
|
||||
.inline-divs {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
}
|
Reference in New Issue
Block a user