簡體   English   中英

如何使用數組中的數據填寫選擇表單標識符-Node.js,EJS,HTML

[英]How to fill in select form identifiers with data from an array - Node.js, EJS, HTML

我目前正在創建一個表單,用戶可以在其中查看SQL數據庫中的信息並在必要時進行更新。 我可以填寫text表單組的數據,但是select表單組沒有填寫。數據來自從route.js文件傳遞的SQL查詢。 這是表格的代碼:

<div class="well">
    <form action="/addMapRoom/<%= communityMap[0].mapID %>/<%= mapRoom %>" method="post">
        <div class="form-group">
            <label>Room Number</label>
            <input type="number" class="form-control" name="roomNumber" value="<%=communityMapData[0].roomNumber%>">
        </div>
        <div class="form-group">
            <label>Resident 1</label>
            <input type="text" class="form-control" name="resident1" value="<%=communityMapData[0].resident1%>">
        </div>
        <div class="form-group">
            <label>Resident 2</label>
            <input type="text" class="form-control" name="resident2" value="<%=communityMapData[0].resident2%>">
        </div>
        <div class="form-group">
            <label>Room standing in community:</label><br>
            <select name="roomColorID" value="<%=communityMapData[0].roomColorID%>">
                <option value='g'>Good Standing - Green</option>
                <option value='y'>Okay Standing - Yellow</option>
                <option value='r'>Bad Standing - Red</option>
            </select>
        </div>
        <div class="form-group">
            <label>Are there any potential student leaders in this room?</label><br>
            <select name="leaderInRoom" value="<%=communityMapData[0].leaderInRoom%>">
                <option value=1>Yes</option>
                <option value=0>No</option>
            </select>
        </div>
        <div class="form-group">
            <label>Do you tend to visit this room often?</label><br>
            <select name="visitMost" value="<%=communityMapData[0].visitMost%>">
                <option value=1>Yes</option>
                <option value=0>No</option>
            </select>
        </div>
        <div class="form-group">
            <label>Are there residents in this room that you do not see often?</label><br>
            <select name="notSeen" value="<%=communityMapData[0].notSeen%>">
                <option value=1>Yes</option>
                <option value=0>No</option>
            </select>
        </div>
        <div class="form-group">
            <label>Please indicate the rooms this room connects with often as well as at least one new fact and interaction with each resident of this room.</label>
            <input type="text" class="form-control" name="factsAndInteractions" value="<%=communityMapData[0].factsAndInteractions%>">
        </div>
</div>

我不確定應該在何處填寫選擇表單標識符的值,因此將不勝感激任何幫助或提示! 謝謝 :)

select標記沒有這樣的稱為“值”的屬性,您需要在option標記中指定它。

您將需要像這樣在EJS文件中使用for循環

<select id="select" name="name">
    <% for(var a=0; a < itemList.length; a++) { %>
     <option value="<%= itemList[a].id %>"><%= itemList[a].info %></option>
    <% } %>
</select>

然后,一旦提交表單,就可以使用name訪問選定的值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM