How do I select item in <SELECT>

K

K. Lobe

list box based on a POST method to the same page.

frm.cmbList.Value=Request.Form("cmbList") doesn't work.

When the page loads, it reloads the <SELECT>, so not sure how to get the
list to go to the item.

Any ideas?

many thnx,
Kevin
 
B

Bob Barrows

K. Lobe said:
list box based on a POST method to the same page.

frm.cmbList.Value=Request.Form("cmbList") doesn't work.

When the page loads, it reloads the <SELECT>, so not sure how to get
the list to go to the item.

Any ideas?
Assuming you've got a window_onload event:
frm.cmbList.Value="<%=Request.Form("cmbList")%>"
Bob Barrows
 
A

Aaron Bertrand - MVP

At the end of the page... you want to make sure this doesn't execute until
after the <select> has loaded.

Something like this... see a JavaScript newsgroup for better syntax and
examples (the only ASP-related part here is getting the ASP variable into
client-side script).

<script>
var selected = 0;
for (i=0; i<document.frm.cmbList.options.length; i++)
{
if (document.frm.cmbList.options.value ==
"<%=request.form("cmbList")%>")
{
selected = i;
i = document.frm.cmbList.options.length;
}
}
document.frm.cmbList.selectedIndex = selected;
</script>

You could also consider building the select list in ASP, e.g.

<%
dim options(3)
options(0) = "foo"
options(1) = "bar"
options(2) = "fu"
options(3) = "barred"
response.write "<select>"
for i = 0 to 3
response.write "<option value='" & options(i) & "'"
if options(i) = request.form("cmbList") then
response.write " selected"
end if
response.write ">" & options(i)
next
response.write "</select>"
%>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top