By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

Keep the value selected in the dropdown field

P: n/a
I have a drop down that defaults to "select" after the page refreshes.
How do I keep the selected value in the dropdown field... I've tried
EVERYTHING and nothing works! :(

<script LANGUAGE="JavaScript">
function getServer(form){
var cdoServerName = document.frmSoftware.cdoServerName.options[document.frmSoftware.cdoServerName.selectedIndex].value;

if (cdoServerName == "Columbus") {
window.location.href =
"../software/default1.asp?v=details&s=Columbus&id=<%=Request.Qu eryString("id")%>";

} else if (cdoServerName == "Gainesville") {
window.location.href =
"../software/default1.asp?v=details&s=Gainesville&id=<%=Request .QueryString("id")%>";

} else if (cdoServerName == "Raliegh") {
window.location.href =
"../software/default1.asp?v=details&s=Raliegh&id=<%=Request.Que ryString("id")%>";

} else if (cdoServerName == "Portland") {
window.location.href =
"../software/default1.asp?v=details&s=Portland&id=<%=Request.Qu eryString("id")%>";

} else if (cdoServerName == "Amarillo") {
window.location.href =
"../software/default1.asp?v=details&s=Amarillo&id=<%=Request.Qu eryString("id")%>";

} else if (cdoServerName == "Harrisburg") {
window.location.href =
"../software/default1.asp?v=details&s=Harrisburg&id=<%=Request. QueryString("id")%>";

} else if (cdoServerName == "Lynchburg") {
window.location.href =
"../software/default1.asp?v=details&s=Lynchburg&id=<%=Request.Q ueryString("id")%>";

} else if (cdoServerName == "Canton") {
window.location.href =
"../software/default1.asp?v=details&s=Canton&id=<%=Request.Quer yString("id")%>";

} else {
window.location.href =
"../software/default1.asp?v=details&s=NOSERVER&id=<%=Request.Qu eryString("id")%>";
}
}
</script>
<meta name="Microsoft Theme" content="none"></head>
<body>
<form name="frmSoftware" method="post">
..........

Please select your location:
<select size="1" name="cdoServerName"
onchange="javascript:getServer();">
<option value="SELECT">SELECT</option>
<%
Dim srv, sshare
'EXECUTING- STORED QUERY- "SLINKS_DROPDOWN"

Do While Not swss.EOF
sid = swss.fields("id").value
srv = swss.Fields("srv_name").value
sshare = swss.Fields("srv_share").value
Response.Write "<option value=""" & srv & """>" & srv & "</option>"
swss.movenext
loop

swss.close
Set swss = Nothing
%>
</select>

Thanks in advance for your help!
~Lisa~
Jul 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

"Lisa" <pe*****@yahoo.com> wrote in message
news:89*************************@posting.google.co m...
I have a drop down that defaults to "select" after the page refreshes.
How do I keep the selected value in the dropdown field... I've tried
EVERYTHING and nothing works! :(
<%

Dim selectedSrv
selectedSrv = Request.Querystring("cdoServerName") ''or request.form
Dim srv, sshare
'EXECUTING- STORED QUERY- "SLINKS_DROPDOWN"

Do While Not swss.EOF
sid = swss.fields("id").value '''You aren't using this anywhere
srv = swss.Fields("srv_name").value
sshare = swss.Fields("srv_share").value '''You aren't using this either
Response.Write "<option value=""" & srv & """"
If srv = selectedSrv Then Response.Write " selected"
Response.Write ">" & srv & "</option>"
swss.movenext
loop

swss.close
Set swss = Nothing
%>
Ray at home
Jul 19 '05 #2

P: n/a
Been wondering this myself and to be honest, I don't think you can (atleast,
not in classic ASP anyway, perhaps in ASP.Net)

I thought something along the lines of;

<select name="somename" value="<%=request.querystring("theID")%>">

or

<option selected value="<%=request.querystring("theID")%>">

But neither seem to work... so I'm out of ideas.

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Lisa <pe*****@yahoo.com> wrote in message
news:89*************************@posting.google.co m...
I have a drop down that defaults to "select" after the page refreshes.
How do I keep the selected value in the dropdown field... I've tried
EVERYTHING and nothing works! :(

<script LANGUAGE="JavaScript">
function getServer(form){
var cdoServerName = document.frmSoftware.cdoServerName.options[document.frmSoftware.cdoServerNam
e.selectedIndex].value;
if (cdoServerName == "Columbus") {
window.location.href =
"../software/default1.asp?v=details&s=Columbus&id=<%=Request.Qu eryString("id
")%>";
} else if (cdoServerName == "Gainesville") {
window.location.href =
"../software/default1.asp?v=details&s=Gainesville&id=<%=Request .QueryString(
"id")%>";
} else if (cdoServerName == "Raliegh") {
window.location.href =
"../software/default1.asp?v=details&s=Raliegh&id=<%=Request.Que ryString("id"
)%>";
} else if (cdoServerName == "Portland") {
window.location.href =
"../software/default1.asp?v=details&s=Portland&id=<%=Request.Qu eryString("id
")%>";
} else if (cdoServerName == "Amarillo") {
window.location.href =
"../software/default1.asp?v=details&s=Amarillo&id=<%=Request.Qu eryString("id
")%>";
} else if (cdoServerName == "Harrisburg") {
window.location.href =
"../software/default1.asp?v=details&s=Harrisburg&id=<%=Request. QueryString("
id")%>";
} else if (cdoServerName == "Lynchburg") {
window.location.href =
"../software/default1.asp?v=details&s=Lynchburg&id=<%=Request.Q ueryString("i
d")%>";
} else if (cdoServerName == "Canton") {
window.location.href =
"../software/default1.asp?v=details&s=Canton&id=<%=Request.Quer yString("id")
%>";
} else {
window.location.href =
"../software/default1.asp?v=details&s=NOSERVER&id=<%=Request.Qu eryString("id
")%>"; }
}
</script>
<meta name="Microsoft Theme" content="none"></head>
<body>
<form name="frmSoftware" method="post">
.........

Please select your location:
<select size="1" name="cdoServerName"
onchange="javascript:getServer();">
<option value="SELECT">SELECT</option>
<%
Dim srv, sshare
'EXECUTING- STORED QUERY- "SLINKS_DROPDOWN"

Do While Not swss.EOF
sid = swss.fields("id").value
srv = swss.Fields("srv_name").value
sshare = swss.Fields("srv_share").value
Response.Write "<option value=""" & srv & """>" & srv & "</option>"
swss.movenext
loop

swss.close
Set swss = Nothing
%>
</select>

Thanks in advance for your help!
~Lisa~

Jul 19 '05 #3

P: n/a
Ray...
god - that was such a "blonde" thing to do... it was a long day :) I
made the change - no more errors... but it still defaults to "select"
no matter what I pick... I tried selectedSrv =
Request.QueryString("cdoServerName")and selectedSrv =
Request.Form("cdoServerName")and neither worked.....can you think of
anything else?

~L~
Jul 19 '05 #4

P: n/a
Then I suppose there's never a match. You see what the code is doing,
right? It's looking at each value that you're pulling from the recordset
and comparing it to the value pulled from the querystring. If it matches,
it writes "selected" in the option tag. So, this is what's supposed to
happen. If it's not, that is when you debug. Does a view source show
"selected" in any of the options? Does a textual comparison ever return
true? Is the cAsE of the comparisons messing things up? Is your value
being pulled from the querystring? Etc.

Ray at work

"Lisa" <pe*****@yahoo.com> wrote in message
news:89**************************@posting.google.c om...
Ray...
god - that was such a "blonde" thing to do... it was a long day :) I
made the change - no more errors... but it still defaults to "select"
no matter what I pick... I tried selectedSrv =
Request.QueryString("cdoServerName")and selectedSrv =
Request.Form("cdoServerName")and neither worked.....can you think of
anything else?

~L~

Jul 19 '05 #5

P: n/a
Ray..
I posetd a follow-up but it never came through - so I'm posting
again...You were right - I didn't even realize what I had done - it
was a VERY long day! Now I no longer get the error message - but the
dropdown still defaults to "select" - i tried Request.QueryString &
Request.Form but neither worked....any other ideas?

~L~

"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in message news:<#N**************@tk2msftngp13.phx.gbl>...
It seems like you're missing a carriage return in your code.

Response.Write "<option value=""" & srv & """" [NEW LINE IN YOUR CODE -
PRESS ENTER]
If srv = selectedSrv Then Response.Write "selected" [NEW LINE IN YOUR CODE -
PRESS ENTER]
Response.Write">" & srv & "</option>"

Ray at home


"Lisa" <pe*****@yahoo.com> wrote in message
news:89**************************@posting.google.c om...
Ray...
What you posted makes sense - but I'm getting the following error:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/AppLauncher/Software/Default1.asp, line 395, column 47
Response.Write "<option value=""" & srv & """" If srv = selectedSrv
Then Response.Write "selected" Response.Write">" & srv & "</option>"

I think I'm missing an "End If" - but I tried doing that in a few
different places.... what am I missing?

~L~

"Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message

news:<es*************@TK2MSFTNGP11.phx.gbl>...
Been wondering this myself and to be honest, I don't think you can (atleast, not in classic ASP anyway, perhaps in ASP.Net)

I thought something along the lines of;

<select name="somename" value="<%=request.querystring("theID")%>">

or

<option selected value="<%=request.querystring("theID")%>">

But neither seem to work... so I'm out of ideas.

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Lisa <pe*****@yahoo.com> wrote in message
news:89*************************@posting.google.co m...
> I have a drop down that defaults to "select" after the page refreshes.
> How do I keep the selected value in the dropdown field... I've tried
> EVERYTHING and nothing works! :(
>
>
>
> <script LANGUAGE="JavaScript">
> function getServer(form){
> var cdoServerName =
document.frmSoftware.cdoServerName.options[document.frmSoftware.cdoServerNam e.selectedIndex].value;
>
> if (cdoServerName == "Columbus") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Columbus&id=<%=Request.Qu eryString("id ")%>";
>
> } else if (cdoServerName == "Gainesville") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Gainesville&id=<%=Request .QueryString( "id")%>";
>
> } else if (cdoServerName == "Raliegh") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Raliegh&id=<%=Request.Que ryString("id" )%>";
>
> } else if (cdoServerName == "Portland") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Portland&id=<%=Request.Qu eryString("id ")%>";
>
> } else if (cdoServerName == "Amarillo") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Amarillo&id=<%=Request.Qu eryString("id ")%>";
>
> } else if (cdoServerName == "Harrisburg") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Harrisburg&id=<%=Request. QueryString(" id")%>";
>
> } else if (cdoServerName == "Lynchburg") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Lynchburg&id=<%=Request.Q ueryString("i d")%>";
>
> } else if (cdoServerName == "Canton") {
> window.location.href =
>
"../software/default1.asp?v=details&s=Canton&id=<%=Request.Quer yString("id") %>";
>
> } else {
> window.location.href =
>
"../software/default1.asp?v=details&s=NOSERVER&id=<%=Request.Qu eryString("id ")%>";
> }
> }
> </script>
> <meta name="Microsoft Theme" content="none"></head>
> <body>
> <form name="frmSoftware" method="post">
> .........
>
> Please select your location:
> <select size="1" name="cdoServerName"
> onchange="javascript:getServer();">
> <option value="SELECT">SELECT</option>
> <%
> Dim srv, sshare
> 'EXECUTING- STORED QUERY- "SLINKS_DROPDOWN"
>
> Do While Not swss.EOF
> sid = swss.fields("id").value
> srv = swss.Fields("srv_name").value
> sshare = swss.Fields("srv_share").value
> Response.Write "<option value=""" & srv & """>" & srv & "</option>"
> swss.movenext
> loop
>
> swss.close
> Set swss = Nothing
> %>
> </select>
>
> Thanks in advance for your help!
> ~Lisa~

Jul 19 '05 #6

P: n/a
Lisa wrote:
Ray..
I posetd a follow-up but it never came through - so I'm posting
again...You were right - I didn't even realize what I had done - it
was a VERY long day! Now I no longer get the error message - but the
dropdown still defaults to "select" - i tried Request.QueryString &
Request.Form but neither worked....any other ideas?

Well, we're not looking over your shoulder, so can you post the code for a
really simplified page that demonstrates your problem? Something we can copy
and paste into our own file and see what is happening? Don't bother with all
the extra html and formatting: just a simple page with a form containing a
single dropdown and submit button...

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #7

P: n/a
Thanks everyone for your help on this... I figured out what the
problem was - kind of difficult to explain but in the onchange event -
i was already getting a function that had the value of the selected
item set. Using Ray's original code

Do until swss.EOF
srv = swss.Fields("srv_name").value
Response.Write "<option value=""" & srv & """"
If srv = strServer Then Response.Write "selected"
Response.Write ">" & srv & "</option>"
swss.movenext
loop

I switched the string value that he gave me (selectedSrv =
Request.QueryString("cdoServerName")with the one I had already set in
the function (strServer) and now it works!!!!!!!

Thanks Guys!
~L~
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message news:<uj*************@TK2MSFTNGP11.phx.gbl>...
Lisa wrote:
Ray..
I posetd a follow-up but it never came through - so I'm posting
again...You were right - I didn't even realize what I had done - it
was a VERY long day! Now I no longer get the error message - but the
dropdown still defaults to "select" - i tried Request.QueryString &
Request.Form but neither worked....any other ideas?

Well, we're not looking over your shoulder, so can you post the code for a
really simplified page that demonstrates your problem? Something we can copy
and paste into our own file and see what is happening? Don't bother with all
the extra html and formatting: just a simple page with a form containing a
single dropdown and submit button...

Bob Barrows

Jul 19 '05 #8

P: n/a
Thanks for the update. Glad it's working.

Ray at work

"Lisa" <pe*****@yahoo.com> wrote in message
news:89**************************@posting.google.c om...
Thanks everyone for your help on this... I figured out what the
problem was -

Jul 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.