Take HTML form and pass values to variables in node.js function

Viewed 7762

Problem Statement: I have a simple HTML form that asks for three numbers from the user. When they hit submit, I would the form to be passed to a node.js file and assign each value to a variable.

Below is my HTML file:

<body>
<form action="/" method="post">
<fieldset>
First number: <input type="number" name="param1"><br>
Second number: <input type="number" name="param2"><br>
Third number: <input type="number" name="param3"><br>
<input type="submit" value="submit" />
</fieldset>
</form>
</body>

And here is the little bit I have for the node.js file:

var http = require('http');
var math = require('mathjs');

    var m = 3;
    var n = 5;
    var o = 7;
    var p = 2;

http.createServer(function(req,res) {

function pleaseSolve () {

    var comp = math.chain(m)
    .add(m)
    .divide(p)
    .multiply(o)
    .done();

res.writeHead(200, {'Content-Type': 'text/html'});
res.end("The answer is " + comp);

}

pleaseSolve();

}).listen(8080);

Instead, I would like a method or something similar that would assign those variables using input from the HTML form rather than me simply hard-coding them.

EDIT: I've already been downvoted and I have been searching the web for two days for an answer for this and I haven't found one. Please be constructive and at least link another post versus downvoting and being non-constructive.

1 Answers
Related