简体   繁体   中英

Replace HTML Select Value with Data from Backend

I trying to do something really simple, but I don't know how. I have an HTML Input select field in a table. If someone writes data in the text field or choose an option from the select field and press the submit Button, the data transfer to the backend via HTTP post. In the backend, the data gets stored in an SQL Database. After that, the page reloads all the textfields having the new value that I reload from the backend and transfer to the Frontend. Now I am trying to do the same with the select input field. I don't want to use a new label to show what has been the last submitted value (the last row of the table in the attached picture). The last submitted value should be shown in the input select field. I try to load the values stored in metadata with the value=" " parameter but that doesn't work. In the normal input text field, it works fine and I get the result that I expected.

Can anybody give me an idea to realize this? My current Code looks like this.

{%for i in range(0, len)%}

                          <tr>
                              <td>{{i+1}}</td>
                              <td>{{tables[i][0]}}</td>
                              <td><input type="text" name="devicename_{{i}}" placeholder="Gerätename" value="{{metadata[i][0]}}"></td>
                              <td><input type="text" name="place_{{i}}" placeholder="Standort" value ="{{metadata[i][1]}}"></td>
                              <td>
                                  <select  name="devicetype_{{i}}" value ="{{metadata[i][2]}}">
                                      <option>Bitte wählen</option>
                                      <option value="Option1">Option2</option>
                                      <option value="Option2">Option2</option>
                                      <option value="Option3">Option3</option>
                                      <option value="deaktiviert">deaktiviert</option>
                                  </select>
                                 <td>"{{metadata[i][2]}}"</td> 
                              </td>

{%endfor%}

Current Frontend result

Thanks for the help. If I have to use JavaScript or PHP for that, please give me help with javascript.

Can't you just use PHP for that, I have a methode but it's only PHP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM