Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 11:41 AM
Ram Raju
Guest
 
Posts: n/a
Default 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("value")%>><%= Rs("Name") %></Option>
<%
Rs.MoveNext
loop
%>
</SELECT>


Can anybody please help me.

Thanks in Advance.
Ram


  #2  
Old July 19th, 2005, 11:41 AM
Ray at
Guest
 
Posts: n/a
Default 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:uu1Pdt26DHA.712@tk2msftngp13.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("value")%>><%= Rs("Name") %></Option>
> <%
> Rs.MoveNext
> loop
> %>
> </SELECT>
>
>
> Can anybody please help me.
>
> Thanks in Advance.
> Ram
>
>[/color]


  #3  
Old July 19th, 2005, 11:41 AM
Aaron Bertrand - MVP
Guest
 
Posts: n/a
Default Re: Option selected

Ummm, first option IS selected by default.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




"Ram Raju" <ramraju@lycos.com> wrote in message
news:uu1Pdt26DHA.712@tk2msftngp13.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("value")%>><%= Rs("Name") %></Option>
> <%
> Rs.MoveNext
> loop
> %>
> </SELECT>
>
>
> Can anybody please help me.
>
> Thanks in Advance.
> Ram
>
>[/color]


  #4  
Old July 19th, 2005, 11:41 AM
Peter Foti
Guest
 
Posts: n/a
Default Re: Option selected

"Ram Raju" <ramraju@lycos.com> wrote in message
news:uu1Pdt26DHA.712@tk2msftngp13.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("value")%>><%= 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


  #5  
Old July 19th, 2005, 11:41 AM
TomB
Guest
 
Posts: n/a
Default 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("value").value &
""""
if RS.Fields("value").value=Request.form("select1") 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:uu1Pdt26DHA.712@tk2msftngp13.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("value")%>><%= Rs("Name") %></Option>
> <%
> Rs.MoveNext
> loop
> %>
> </SELECT>
>
>
> Can anybody please help me.
>
> Thanks in Advance.
> Ram
>
>[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles