Option selected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ram Raju

    Option selected

    Hi All,

    I am displaying few values in a List box. I would like to put first
    item as selected by default.
    i.e <option value="some value" selected>Name</option>

    Here is my code.

    <SELECT size=15 id=select1 name=select1>
    <% do while not Rs.EOF %>
    <Option value=<%=Rs("va lue")%>><%= Rs("Name") %></Option>
    <%
    Rs.MoveNext
    loop
    %>
    </SELECT>


    Can anybody please help me.

    Thanks in Advance.
    Ram


  • Ray at

    #2
    Re: Option selected

    The first item will be selected by default, will it not? What happens when
    you load the page?

    Ray at work

    "Ram Raju" <ramraju@lycos. com> wrote in message
    news:uu1Pdt26DH A.712@tk2msftng p13.phx.gbl...[color=blue]
    > Hi All,
    >
    > I am displaying few values in a List box. I would like to put first
    > item as selected by default.
    > i.e <option value="some value" selected>Name</option>
    >
    > Here is my code.
    >
    > <SELECT size=15 id=select1 name=select1>
    > <% do while not Rs.EOF %>
    > <Option value=<%=Rs("va lue")%>><%= Rs("Name") %></Option>
    > <%
    > Rs.MoveNext
    > loop
    > %>
    > </SELECT>
    >
    >
    > Can anybody please help me.
    >
    > Thanks in Advance.
    > Ram
    >
    >[/color]


    Comment

    • Aaron Bertrand - MVP

      #3
      Re: Option selected

      Ummm, first option IS selected by default.

      --
      Aaron Bertrand
      SQL Server MVP
      Please contact this domain's administrator as their DNS Made Easy services have expired.





      "Ram Raju" <ramraju@lycos. com> wrote in message
      news:uu1Pdt26DH A.712@tk2msftng p13.phx.gbl...[color=blue]
      > Hi All,
      >
      > I am displaying few values in a List box. I would like to put first
      > item as selected by default.
      > i.e <option value="some value" selected>Name</option>
      >
      > Here is my code.
      >
      > <SELECT size=15 id=select1 name=select1>
      > <% do while not Rs.EOF %>
      > <Option value=<%=Rs("va lue")%>><%= Rs("Name") %></Option>
      > <%
      > Rs.MoveNext
      > loop
      > %>
      > </SELECT>
      >
      >
      > Can anybody please help me.
      >
      > Thanks in Advance.
      > Ram
      >
      >[/color]


      Comment

      • Peter Foti

        #4
        Re: Option selected

        "Ram Raju" <ramraju@lycos. com> wrote in message
        news:uu1Pdt26DH A.712@tk2msftng p13.phx.gbl...[color=blue]
        > Hi All,
        >
        > I am displaying few values in a List box. I would like to put first
        > item as selected by default.
        > i.e <option value="some value" selected>Name</option>
        >
        > Here is my code.
        >
        > <SELECT size=15 id=select1 name=select1>
        > <% do while not Rs.EOF %>
        > <Option value=<%=Rs("va lue")%>><%= Rs("Name") %></Option>
        > <%
        > Rs.MoveNext
        > loop
        > %>
        > </SELECT>[/color]

        You could use some sort of flag to indicate that it's the first item. Also,
        you should surround your attribute values in quotes.

        <select size="15" id="select1" name="select1">
        <%
        Dim firstOption
        firstOption = True

        Do While Not Rs.EOF
        Response.Write "<option value=""" & Rs("value") & """"
        If firstOption = True Then
        Response.Write " selected"
        firstOption = False
        End If
        Response.Write ">" & Rs("Name") & "</option>"
        Rs.MoveNext
        Loop
        %>
        </select>

        Hope this helps.
        Regards,
        Peter Foti


        Comment

        • TomB

          #5
          Re: Option selected

          Do you mean when the form is posted, you want to display the value selected
          in the Select box?


          <%
          Do while not rs.eof
          Response.write "<option value=""" & RS.Fields("valu e").value &
          """"
          if RS.Fields("valu e").value=Reque st.form("select 1") then
          Response.write " selected"
          end if
          Response.write ">" & RS.Fields("Name ") & "</option>" & vbCrlf
          Rs.MoveNext
          Loop
          %>

          "Ram Raju" <ramraju@lycos. com> wrote in message
          news:uu1Pdt26DH A.712@tk2msftng p13.phx.gbl...[color=blue]
          > Hi All,
          >
          > I am displaying few values in a List box. I would like to put first
          > item as selected by default.
          > i.e <option value="some value" selected>Name</option>
          >
          > Here is my code.
          >
          > <SELECT size=15 id=select1 name=select1>
          > <% do while not Rs.EOF %>
          > <Option value=<%=Rs("va lue")%>><%= Rs("Name") %></Option>
          > <%
          > Rs.MoveNext
          > loop
          > %>
          > </SELECT>
          >
          >
          > Can anybody please help me.
          >
          > Thanks in Advance.
          > Ram
          >
          >[/color]


          Comment

          Working...