建站代码网

热门标签

下拉菜单: 让合适的出现在顶部

下拉菜单是允许固定的用户输入的很好的方式。总是让正确的选项出现在顶部是像添加一些重言式容易的。在这个例子中我们有17个选项(16个U.S 州和选择一个州的选项)。按照用户输出(或者缺乏这些)适合的选项是像在顶部显示一样选择的。

<% u_state=request.form("u_state") %> <form action="<%= request.servervariables("script_name") %>" method="post"> <select name="u_state"> <option<% if u_state="" then %> selected<% end if %>> Select a State </option> <option<% if u_state="AL" then %> selected<% end if %> value="AL"> Alabama </option> <option<% if u_state="AR" then %> selected<% end if %> value="AR"> Arkansas </option> <option<% if u_state="CA" then %> selected<% end if %> value="CA"> California </option> <option<% if u_state="CO" then %> selected<% end if %> value="CO"> Colorado </option> <option<% if u_state="CT" then %> selected<% end if %> value="CT"> Connecticut </option> <option<% if u_state="DE" then %> selected<% end if %> value="DE"> Delaware </option> <option<% if u_state="MD" then %> selected<% end if %> value="MD"> Maryland </option> <option<% if u_state="NE" then %> selected<% end if %> value="NE"> Nebraska </option> <option<% if u_state="NH" then %> selected<% end if %> value="NH"> New Hampshire </option> <option<% if u_state="NJ" then %> selected<% end if %> value="NJ"> New Jersey </option> <option<% if u_state="NY" then %> selected<% end if %> value="NY"> New York </option> <option<% if u_state="PA" then %> selected<% end if %> value="PA"> Pennsylvania </option> <option<% if u_state="TN" then %> selected<% end if %> value="TN"> Tennessee </option> <option<% if u_state="TX" then %> selected<% end if %> value="TX"> Texas </option> <option<% if u_state="VA" then %> selected<% end if %> value="VA"> Virginia </option> </select> <input type="submit" value="Submit"> </form> <p> <% if u_state = "" then %> Either this is the first time the page is being used<br> or the user selected the Select A State choice. <% else %> <%= u_state %> was selected by the user. <% end if %> </p>


X