I have started using nodejs and trying to make a website that consists of two drop-down lists. The values selected in them will have to be passed as arguments to a MySQL procedure (and then a table to be displayed on the webpage).
So far, I have been able to (by adapting other people's codes) display the table on the webpage without the use of drop-down list, i.e. manually typing argunment in users.js.
So, the issue is to get the two values from drop-down list and then I will use placeholders in my query to use them as arguments. Any help and suggestion is appreciated. Here's my project folder tree.
users.js
var express = require('express');
var router = express.Router();
var db = require('../database');
router.get('/user-list', function(req, res, next) {
db.query("TRUNCATE stack_Compare");
db.query("SET max_sp_recursion_depth=100");
db.query("CALL insertMain(?,?)"); //here I manually type arguments but want to actually get them from drop down lists.
var sql="SELECT * FROM stack_Compare";
db.query(sql, function (err, results, fields) {
if (err) throw err;
res.render('user-list', { title: 'User List', userData: results});
});
});
module.exports = router;
the form code in user-list.ejs
<form action="/users/input" method="POST">
<fieldset style="width:50%">
<select class="selectpicker" data-style="btn-info" name="selectpicker">
<optgroup label="Select Table">
<option name="" value="0">Starting Station</option>
<option name="table1" value="1">A</option>
<option name="table2" value="2">B</option>
<option name="table3" value="3">C</option>
</optgroup>
</select>
to
<select class="selectpicker" data-style="btn-info" name="selectpicker">
<optgroup label="Select Table">
<option name="" value="0">Destination Station</option>
<option name="table1" value="1">S</option>
<option name="table2" value="2">O</option>
<option name="table3" value="3">G</option>
</optgroup>
</select>
<button class="dropbtn"><b>GO</b></button>
</fieldset>
</form>
I have thought of adding the following code in users.js but am stuck as to how they should pick distinct data from the form.
router.get('/form', function(req, res, next) {
res.render('users-form');
});
// this script to fetch data from drop-down lists
router.post('/input', function(req, res, next)
})
