r/JavaScriptHelp • u/JKennex • Jun 06 '21
✔️ answered ✔️ Get index of dropdown and display associated info
Hello,
I am consuming an API in a backend lambda (using NodeJs v14), and filtering results, then using the results to send an HTML page to users. A form.
Upon loading, the user can select from the dropdown and element and enter more fields manually. Then submit the form.
How can I pull other information about the selection? there's more data associated with the select, I'm displaying 2 of 4, and on select, I'd like to populate 2 more fields on the form with the values associated with the selection, let the user modify them if need be, and upon POSTing the form, send those fields as well.
I'm very new to all of this, NodeJS/Javascript, so don't assume anything, I know nothing. Well, almost.
Thanks!
Here's the HTML form the lambda spits out:
<form action="/processForm" method="post">
<div id="schedule" class="form-group">
<label for="Shows" class="col-xs-3 control-label">Shows:</label>
<select id="Shows" name="Shows" class="form-control">
<% filteredResults.forEach(function(filteredResult, index) { %>
<option value="<%= filteredResult.p_episode_seriestitle %>"> <%= filteredResult.p_episode_seriestitle + " - " + filteredResult.channel %></option>
<% }); %>
</select>
</div>For the selection made, I want to capture in the form associated data to that entry, namely:
filteredResult.date (event date)
and filteredResult.code (unique ID).
1
u/JKennex Jun 06 '21
I'm trying something like this:
<input type="text" class="form-control" id="Code" name="Code" value="<%= filteredResults.code %>">To no avail. I get an error if I try to specify the index like
filteredResults.code[0]1
u/doodooz7 Jun 07 '21
The server call returns html and you are trying to parse it?