Auto-Filling HTML Fields - Using NodeJs & mySQL
<p>I am currently using NodeJS and mySQL for a project and am learning as I go.
One thing I'm struggling to find an answer to is how to prefill certain fields upon selection of a drop-down option. </p>

<p>Here is my code currently before I explain further. I may be doing this all wrong to start with. I'm only going to put in snippets to not overpower the question.</p>

<p>This for Example is the GET which fetches the current values (var db = require...):</p>

<pre><code>router.get('/', function(req, res) {
db('SELECT * FROM clients', function (err, result) {
        db('SELECT * FROM staff', function (err, result2) {
            .......
                      if (!err) {
                         res.render('page', {
                             title: 'Page',
                             clients: result,  staff: result2,...
                                        });
                                    }
                              else
                              console.log('Error while performing query');
</code></pre>

<p>One thing I'm sure I'm doing wrong is the method I'm using to do query after query. However, I'll get over that for now unless anyone has any advice there it would be great. My biggest question is though:
 Currently I am feeding in the info to the dropdown box and then these are POSTed on submit which is fine. Many of the dropdowns are standalone. But about 2/3 of the dropdowns are related to textboxes and I want to see how can I get them to auto-populate on selection of the name. This is an example of some current HTML //.ejs)</p>

<pre><code>&lt;div class = "col-md-2"&gt;
            &lt;select class="form-control" id="clientName"  required &gt;
                &lt;option&gt;&lt;/option&gt;
                &lt;% clients.forEach(function (clients) { %&gt;
                &lt;option&gt; &lt;%= clients.FirstName %&gt; &lt;%=clients.LastName %&gt; &lt;% }) %&gt; &lt;/option&gt;
            &lt;/select&gt;
        &lt;/div&gt;
</code></pre>

<p>.....</p>

<pre><code>&lt;div class = "col-md-2"&gt;
            &lt;label&gt;PASS ID: &lt;/label&gt;
        &lt;/div&gt;
        &lt;div class = "col-md-2"&gt;
            &lt;input type="text" class="form-control" name="passID" id="passID" required&gt;
            &lt;% clients.PassID %&gt;
            &lt;/input&gt;
        &lt;/div&gt;
</code></pre>

<p>What I would like to happen, is on selection of the Clients name, their ID is entered in the textbox. (I just last tried the <code>&lt;% clients.PassID %&gt;</code> there but it did not work so I just left it.) It is most likely how I'm sending it on the GET or is there anything that I can do on the front end to link the fields on selection? Is it that I am sending it the info in the GET which is static on the page?</p>

<p>Thanks in advance for any help</p>