0

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.

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
  • You could use selected="selected" for the option that was chosen (see https://stackoverflow.com/questions/3518002/how-can-i-set-the-default-value-for-an-html-select-element) – René Steeman Sep 24 '22 at 07:50

0 Answers0