Dynamic default value a menu box troubles

Discussion in 'ASP General' started by djjohnst, May 14, 2007.

  1. djjohnst

    djjohnst Guest

    I am trying to fill out a form from a record set and have a few menu
    boxes that have a static list of values. I want to fill out the
    default value with the variable from the recordset. The one solution i
    thought of is as follows:

    <td colspan="3"><select name="WorkshopType"
    id="WorkshopType">

    <% if WorkshopType = "Information Session" then
    %>
    <option value="Information Session" selected>Information Session</
    option>
    <option value="Interview Practice Clinic">Interview
    Practice Clinic</option>
    <option value="Senior Job Search Seminar">Senior Job
    Search Seminar</option>
    <% elseif WorkshopType = "Interview Practice Clinic" then
    %>
    <option value="Information Session">Information Session</option>
    <option value="Interview Practice Clinic"
    selected>Interview Practice Clinic</option>
    <option value="Senior Job Search Seminar">Senior Job
    Search Seminar</option>
    <% elseif WorkshopType = "Senior Job Search Seminar" then
    %>
    <option value="Information Session">Information Session</option>
    <option value="Interview Practice Clinic">Interview
    Practice Clinic</option>
    <option value="Senior Job Search Seminar"
    selected>Senior Job Search Seminar</option>
    <%end if%>

    </select>

    This works great. However, this menu only had 3 options so it was easy
    to implement. I also have menus with 31 different options. The way i
    came up with was to do something like this:

    <select name="WorkshopMonth" id="WorkshopMonth">
    <option Value = "<%response.Write(WorkshopMonth)%>" selected><
    %response.Write(WorkshopMonth)%></option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    </select>

    Yes, this works, but it lists the default value twice. This isn't the
    end of the world but I would like to clean it up a bit. Is there a
    better way to do this?
    djjohnst, May 14, 2007
    #1
    1. Advertising

  2. djjohnst

    djjohnst Guest

    Nevermind, I guess the easiest way for me to do it is by doing it like
    this:

    <td width="103">Month
    <select name="WorkshopMonth" id="WorkshopMonth">
    <option value="1" <%if WorkshopMonth = 1 then
    response.Write(" selected")%>>1</option>
    <option value="2" <%if WorkshopMonth = 2 then
    response.Write(" selected")%>>2</option>
    <option value="3" <%if WorkshopMonth = 3 then
    response.Write(" selected")%>>3</option>
    <option value="4" <%if WorkshopMonth = 4 then
    response.Write(" selected")%>>4</option>
    <option value="5" <%if WorkshopMonth = 5 then
    response.Write(" selected")%>>5</option>
    <option value="6" <%if WorkshopMonth = 6 then
    response.Write(" selected")%>>6</option>
    <option value="7" <%if WorkshopMonth = 7 then
    response.Write(" selected")%>>7</option>
    <option value="8" <%if WorkshopMonth = 8 then
    response.Write(" selected")%>>8</option>
    <option value="9" <%if WorkshopMonth = 9 then
    response.Write(" selected")%>>9</option>
    <option value="10" <%if WorkshopMonth = 10 then
    response.Write(" selected")%>>10</option>
    <option value="11" <%if WorkshopMonth = 11 then
    response.Write(" selected")%>>11</option>
    <option value="12" <%if WorkshopMonth = 12 then
    response.Write(" selected")%>>12</option>
    </select>
    djjohnst, May 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. King of Red Lions

    CSS menu troubles (Internet Explorer)

    King of Red Lions, Jun 28, 2004, in forum: HTML
    Replies:
    2
    Views:
    588
    Mark Parnell
    Jun 29, 2004
  2. Gnarlodious
    Replies:
    4
    Views:
    17,588
    elizas
    May 5, 2010
  3. naijacoder naijacoder

    How to create dynamic menu with user roles (Treeview menu)

    naijacoder naijacoder, Sep 27, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    345
    naijacoder naijacoder
    Sep 27, 2004
  4. Robin
    Replies:
    2
    Views:
    173
    Robin
    Apr 9, 2004
  5. Krustov

    Form box menu - force the drop down menu

    Krustov, Dec 5, 2006, in forum: Javascript
    Replies:
    2
    Views:
    168
    Krustov
    Dec 5, 2006
Loading...

Share This Page