Drop down without saving the selected value after sending back

I use classic asp, I have a drop-down list that the user selects and then click submit. After they click the button, the drop-down list returns to the default value instead of what they selected. Is there a way to keep the drop state between post-spins and not return to default? If necessary, you can send a sample code. Thank!

+3
source share
2 answers

You need to β€œselect” the servers according to the values ​​that the user set.

<select id="cars">
  <option value="volvo" 
      <%
      if request.form("cars") = "volvo" then 
          response.write("selected") 
      end if %>
      >Volvo</option>
  <option value="Saab" 
      <%
      if request.form("cars") = "Saab" then 
          response.write("selected") 
      end if %>
      >Saab</option>
  <option value="Mercedes" 
      <%
      if request.form("cars") = "Mercedes" then 
          response.write("selected") 
      end if %>
      >Mercedes</option>
  <option value="Audi" <%
      if request.form("cars") = "Audi" then 
          response.write("selected") 
      end if %>
      >Audi</option>
</select>

Of course, you may want to create your own function yourself to avoid all this pattern.

<% 
sub option(value, data, select_id) 
    Response.Write("<option value=""" & value & """)
    if request.form(select_id) = value then 
        Response.Write("selected") 
    end if
    Response.Write(">" & data & "</option>")
end sub
%>
' (...)
<select id="cars">
    <% option("volvo", "Volvo", "cars") %>
    <% option("Saab", "Saab", "cars") %>
    <% option("Mercedes", "Mercedes", "cars") %>
    <% option("Audi", "Audi", "cars") %>
</select>

select_id, , select .

+10

javascript HTML : HTML:

JavaScript: On submit

http://www.daniweb.com/forums/thread105485.html

0

Source: https://habr.com/ru/post/1737925/


All Articles