共用方式為


Retain a visitor-specified value in a drop down list

Here's a tip that Jim Buyens * , a FrontPage MVP, contributed some time ago for retaining a visitor-specified value in a drop down list. If you're working with databases in FrontPage, the Database Results Wizard is probably what you use most, if not every, time you want to show database results on a Web page. When you use a drop-down list to display values from a database, you have probably noticed that after you submit the form, the selection in the drop-down list referts to the first item in the list.  Jim's tip shows you how to make the drop-down list display the value that the visitor specified.

Switch to Code view and add a script such as the following just before the end of your form (that is, just before the </form> tag.)

 <script>
   for (i = 0; i < document.forms[0].CategoryID.options.length; i++)
   {
      if (document.forms[0].CategoryID.options[i].value == "<%=request.form("CategoryID")%>")
      {
         document.forms[0].CategoryID.selectedIndex = i;
         break;
      }
   }
</script>

This sample code assumes that the name of the drop-down list box is CategoryID. To make the script work with your list box, change all four occurrences of the name CategoryID to the name of your list box. This will be the name you specify under Submit Values From This Field option on page four of the wizard.


* Jim Buyens is the author of ten computer books, including most recently Microsoft Office FrontPage 2003 Inside Out, from Microsoft Press, ISBN 0-7356-1510-1.

Comments