I'm currently making an app in node.js and want to find a way to get input from html. Currently, I want a drop down menu to call a function and use the choice as input into the function. However, when I try calling a basic function (like console.log('hello world');), nothing happens. I'm using the http module to create a server and another function to return html to the user on a localhost. Here's a snippet of my code.
const http = require('http');
http.createServer(function (req, res) {
var html = buildGreeter(req);
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-Length': html.length,
'Expires': new Date().toUTCString()
});
res.end(html);
}).listen(8080);
function buildGreeter(req) {
var test = 'Test test test ';
var input = '<select onchange = "myFunc()"> <option> foo </option> <option> bar </option> </select>';
return '<!DOCTYPE html> <html><header></header><body>' + test + input + '</body></html>';
}
function myFunc(variable){
console.log(variable);
}
Should I be using another module? I know that a lot of examples online had the data sent to the server (ie via Ajax), but since I don't have a server for this project I don't know how applicable that solution is.
Thanks for the help in advance!