NodeJS Auto-Update Dropdown menu based on MySQL queries

Multi tool use
NodeJS Auto-Update Dropdown menu based on MySQL queries
This is my first project working with Express & NodeJS so please bear with me, as I a a total newbie to JavaScript.
I am currently trying to figure out how to create a dropdown menu that changes its values based on the options "pais", "titulacion" and "destino" selected from this DB (outgoing):
+--------+-----------+------------+-----------+------------+----+
| nombre | apellidos | destino | pais | titulacion | id |
+--------+-----------+------------+-----------+------------+----+
| John | Martinez | UPMC | Francia | GIB | 1 |
| Marta | López | HEC | Francia | GITST | 2 |
| Amadeo | Perez | Linköping | Finlandia | GITST | 3 |
+--------+-----------+------------+-----------+------------+----+
I want to make it so that if I select "Francia" on the dropdown list, the other dropdown list for "destino" will only show those options that have pais="Francia".
This is part of the code I have on my router file:
router.get('buscador/pais/:pais/universidad/:universidad/titulacion/:titulacion/curso/:curso', function(req, res, next) {
sql.connect(config).then(() => {
return sql.query(`SELECT pais FROM outgoing`)}).then(result => {
console.log(result);
res.render('buscador', {paises: result})
}).catch(err => {
console.log(err);
})
})
It's incomplete because I am not sure if this is the best way to do this.
Then my form looks like this:
<section class="main" id="mainSection>
<form name="buscador" method="get" action="/buscador">
<div class="contenido buscador">
<select>
<% for (var i=0; i < paises.length; i++) { %>
<option> <%= paises[i] %></option>
<% } %>
</select>
<div class="boton-buscador">
<input class="submit" type="submit" value="Enviar" name="submit" onsubmit="return validar(email)">
</div>
</form>
I was thinking maybe creating a middleware for this would be best but I still do not quite understand how to use them.
If you guys could help me figure out how to do this I would be very grateful.
Thank you very much.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.