I am very new in node Js and I am creating one simple calculator using express . while post call it's not going into the switch case method and not doing the math operation and giving default result. This is my calc.html under public
<html>
<head>
<title> Login Page </title>
</head>
<body bgcolor="orange">
<div align="center">
Welcome To Calcualtor Page <br/><br/>
<form action="calculate" method="post" target="result">
Enter number a: <input type="text" name="a"> <br>
Enter number b: <input type="text" name="b"> <br/>
<input type="submit" name="action" value="Add">
<input type="submit" name="action" value="Sub">
</form>
<hr/>
<iframe name="result" src="" width="200" height="200">
</iframe>
</div>
</body>
</html>
and this is app.js
var express = require('express');
var bodyParser = require('body-parser');
var calc = require('./routes/calculate');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static("public"));
app.use('/calculate', calc);
module.exports = app;
And this is calculate.js under routes
var express = require('express');
var router = express.Router();
router.post('/', function(request, response, next) {
var a=request.body.a;
var b=request.body.b;
var c= a+b;
switch(request.params.operation) {
case 'Add':
var answer = a + b;
response.send(answer);
break;
case 'Sub':
var answer = a - b;
response.send(answer);
break;
default:
response.send("default");
}
});
module.exports = router;