I'm working on a node.js project that involves selecting someones' name and redirecting the user for more information. However, when I try to console.log the result, just to check that I can retrieve the values, I get nothing. Below is an example of my code:
function displayDetailed(data, req) {
names = data[0];
var input = '<select name = "dropDown" onChange = "testing(this)">;
for (var i = 0; i < names.length; i++) {
input += '<option value= "' + i + '" name = "employee" > ' + names[i] + ' </option>';
}
input += '</select><br>';
var myData = {
test: req.body
}
console.log(myData);
return '<!DOCTYPE html><head></head><body>' + input + '</body></html>';
}
function testing(name) {
console.log('Testing! ' + name);
}
Clearly, I just want the employee's name to be printed off onto the console for the moment. However, nothing is popping up on the console, be it the name or any errors.
I've also tried multiple solutions I've seen on other StackOverflow posts ( Example, Example1 ). That's where I got the idea for the test var. For some reason, the request's body does not exist when I try to call it and just returns undefined
.
I also can't call document.getElementById
since node.js doesn't have a DOM. The solutions linked implement this function, which I cannot call because node.js doesn't allow me to call the html document that the user is working on.
This function will be returning an HTML string to a res.send call within an express app.get.