Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6

    Unanswered: For/next loop to populate dropdown

    I've obviously outsmarted myself here. I'm trying to simplify this:

    # of passengers: <select size="1" name="PassQuant">
    <option selected>1</option>
    <option>2</option>
    ...
    <option>25</option>
    </select>

    with this:

    <p> # of passengers: <select size="1" name="PassQuant">
    <% For X=1 to 25
    Response.Write("<option>" & X & "</option>")
    Next X %>
    </select></p>

    which isn't working. Anyone spot why, or am I stuck doing it the long way?

    TIA
    Paul

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Finally found my own stupid mistake. When looking at the test site from outside, I didn't get any kind of informative error. Ran it from inside the firewall and got a compile error pointing to:

    Next X

    Did a little research and found that ASP didn't want the "X" like VBA does. Dropping that worked.
    Paul

  3. #3
    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    191
    Just a personal preference.... I would do it this way... (and you're also going to want to pass a value I think...)

    <p> # of passengers: <select size="1" name="PassQuant">
    <% For X=1 to 25 %>
    <option value="<%=X%>"><%=X%></option>
    <%Next %>
    </select></p>

    It helps me keep my bearings on where the html is versus where the asp is.
    Tim

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Thanks Tim. I guess I'm not sure what I'm gaining there, or more likely not understanding what you're saying. I assume this is producing something that I use elsewhere, where:

    1 = Sedan
    2 = Limo
    3 = Bus

    and the user will see "Sedan" but 1 will be inserted into the db. In this case, they're the same, so why the second value? I've tested mine and it does pass the selected value.
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •