Javascript 如何从选项列表中获取一项

Javascript 如何从选项列表中获取一项,javascript,node.js,postgresql,express,Javascript,Node.js,Postgresql,Express,我试图从ejs选项列表中从数据库中获取一项 这是我的密码 <form action="/chords/id" method='POST'> <select name="root" id="root"> <%chords.forEach(function(chord){%> <option value="<%=chord.id%>"><%=chord.root%></opt

我试图从ejs选项列表中从数据库中获取一项

这是我的密码

<form action="/chords/id" method='POST'>
    <select name="root" id="root">
        <%chords.forEach(function(chord){%>
            <option value="<%=chord.id%>"><%=chord.root%></option>
       <% }) %>
    </select>
    <select name="type" id="type">
        <%chords.forEach(function(chord){%>
            <option value=""><%=chord.type%></option>
       <% }) %>
    </select>
    <select name="extension" id="extension">
        <%chords.forEach(function(chord){%>
            <option value=""><%=chord.extension%></option>
       <% }) %>
    </select>


    <input type="submit" value='SUBMIT'>

</form>


我的数据库有4个键:root、type、extension和note。我的想法是从选项列表中选择root、type和extension,然后返回和弦的音符并在页面上打印chord.note。我该怎么做?我应该在路线的表单操作中传递什么?请帮助我,谢谢

我不知道ejs,但在JavaScript中,我们无法在提交事件时执行类似操作:

const select = event.target.elements['select']
const optionValue = select.options[select.selectedIndex].value

console.info('Value:', optionValue)

HTH

我不知道ejs,但在JavaScript中,我们无法在提交事件时执行类似操作:

const select = event.target.elements['select']
const optionValue = select.options[select.selectedIndex].value

console.info('Value:', optionValue)

HTH

您忘记在
选项上设置扩展名和类型的chord.id


您忘了在
选项上设置扩展名和类型的chord.id