I have a simple HTML web form that contains a select box. I would like to set the options to use the results of my MSSQL query. (It's a list of product numbers)
Here is what I currently have:
var {TYPES, Request, Connection} = require('tedious');
// Create connection to database
var config = {
userName: 'user',
password: '123123',
server: 'someserver',
options: {
instanceName: 'test'
}
};
var connection = new Connection(config);
// Attempt to connect and execute queries if connection goes through
connection.on('connect', (err) => {
if(err){
console.log(err);
}
run();
});
function run(request, result){
request = new Request("USE Database; SELECT PartNumber FROM dbo.Master ORDER BY PartNumber;", (err) =>{
if(err){
console.log(err);
connection.close();
}
connection.close();
});
var result = "";
request.on('row', (columns) =>{
columns.forEach((column) =>{
result+= column.value + " ";
});
console.log(result);
result = "";
});
connection.execSql(request);
}
<div class="row">
<div class="col span-1-of-3">
<label for="partnumber">PartNumber</label>
</div>
<div class="col span-2-of-3">
<select>
<option required></option>
</select>
</div>
</div>
I am having troubles finding any example of this on the Web. I want to click the Select Box and my list from the JavaScript code appear. I can run the console and see the results, but can not populate the Options.