473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Keep the value selected in the dropdown field

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
8 10171

"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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: cmc_dermo | last post by:
I have a form that has a select list. A user chooses a value and the page refreshes showing the selected value in the dropdown box. So I want to use Javascript to get the selected query from...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
0
by: Kannan.M.R | last post by:
Hi, I have a problem in assigning the selected value in the dropdown to a hidden control. It goes like this. I have a repeater control. In the repeater control’s item template, I have a...
5
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities"...
0
by: Matthias S. | last post by:
Hi there, first of all, sorry for the lengthy post, but restrictions in my languages skills and the nature of the problem account for it. I've got the following situation: I'm creating a...
5
by: Drew | last post by:
I am building an application for inserting and updating one field in a database. The database is in SQL Server and I am using Classic ASP. I have a dropdown listbox that is populated with names,...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
3
by: John | last post by:
I have two dropdown lists that I have bound to a datatable and set the DataTextField and DataValueField for. Both lists show the values I expect from the database. However, when I need to access...
17
by: Nyris | last post by:
I have this code used for the navigation on an HTML page. It's an accordion style dropdown menu. Everything works fine I just need to change it so that the submenuheader class allows it to be a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.