How can I get the dropdown's selected value

L

London

Hello
Can you help me.
By ASP
How can I get the dropdown(control'name)'s selected value?
What is it's property'name?
 
B

Bob Barrows

London said:
Hello
Can you help me.
By ASP
How can I get the dropdown(control'name)'s selected value?
What is it's property'name?

Give the dropdown element a name, using its name property.

Then, in the asp page to which you are submitting the form, just do this (if
using POST):
<%
selectedvalue = request.form("name_of_dropdown")
.....
%>

or this, if using GET:
<%
selectedvalue = request.querystring("name_of_dropdown")
.....
%>

HTH,
Bob Barrows
 
R

Randy Rahbar

By ASP
How can I get the dropdown(control'name)'s selected value?
What is it's property'name?

Using ASP, you'll have to resubmit your form first. After submitting your
form, try the following...

'Let's assume the name of your dropdown list is ControlName.
Response.Write request("ControlName")
 
R

Ray at

<select name="XYZ">
<option value="1">One</option>
<option value="2">Two</option>
</select>

If method="post" -
Request.Form("XYZ")

If method="get"
Request.Querystring("XYZ")

Ray at work
 
P

Phillip Windell

First it has to be in a Form and the Form has to be "Submitted" to an
ASP page. If the control's Name is "DdList", then the ASP page you
submitted to would retreive it with any one of these:

Request.Form("DdList")

How you handle it from that point is up to you.


--

Phillip Windell [CCNA, MVP, MCP]
(e-mail address removed)
WAND-TV (ABC Affiliate)
www.wandtv.com
 
G

Guinness Mann

louxiangyu2000 said:
Hello
Can you help me.
By ASP
How can I get the dropdown(control'name)'s selected value?
What is it's property'name?
Man, you *are* an idoit!

-- Guinness
 
R

Ray at

Don't listen to him, London. Everyone posting here started out as an egg
and a sperm and had to take it from there. You can post any questions here,
from total beginner level, to total expert level. Don't be discouraged by
the idoits [sic] who post nonsense.

Ray at work
 
G

Guinness Mann

"Ray at <% said:
Don't listen to him, London. Everyone posting here started out as an egg
and a sperm and had to take it from there. You can post any questions here,
from total beginner level, to total expert level. Don't be discouraged by
the idoits [sic] who post nonsense.

Ray at work

P.S. I notice you didn't answer his question... :)
 
M

Michael Ralph

Actually you can just:
Request("XYZ")

It will look for querystring first then post if no
querystring is present. I use this ocassionally because
sometimes you need a user to post info to a page and I
may also have a direct link from another page with posted
info in the querystring as a shortcut.
 
R

Ray at

That's totally inefficient and bound to cause bugs. You should always
explicitly state which collection you want to look in. All shortcuts waste
future time.

Ray at home
 
B

Bob Barrows

Michael said:
Actually you can just:
Request("XYZ")

It will look for querystring first then post if no
querystring is present. I use this ocassionally because
sometimes you need a user to post info to a page and I
may also have a direct link from another page with posted
info in the querystring as a shortcut.
This is not recommended. In addition to slowing down your code (due to
forcing all the Request collections to be searched, not just the Form and
Querystring collections), it can cause unintended results:
If you happen to use a control name in your form that is the same as the
name of a variable in the servervariables collection (such as "URL"), you
will get the servervariable value, not the form or querystring value.

It is better to do something like this:

sVar = Request.Form("XYZ")
if len(sVar) = 0 then sVar = Request.Querystring("XYZ")

Bob Barrows
 
L

London

Thank you very much.
but
I wrote this code:

dim xy
Response.Write "<FORM>"
Response.Write "<B><TR><SELECT name=""select1"" Width=394px>"
Response.Write "<OPTION value=""1"">One</OPTION>"
Response.Write "<OPTION value=""2"">Two</OPTION>"
Response.Write "</SELECT></TR></B>"
Response.Write "</FORM>" & Chr(13)
xy=Request.Querystring("select1")
Response.Write "<P><input type=""text"" id=""text1"" name=""text1""></P>"
Response.Write "<P><input type=""button"" value=""ButtonX""
onclick=""text1.value='" & xy & "';"" METHOD=""get"" id=button1
name=button1></P>"

I click the button(ButtonX),but the testbox(text1) is none.
Can you more help me
 
B

Bob Barrows

London said:
Thank you very much.
but
I wrote this code:

dim xy
Response.Write "<FORM>"
Response.Write "<B><TR><SELECT name=""select1"" Width=394px>"
Response.Write "<OPTION value=""1"">One</OPTION>"
Response.Write "<OPTION value=""2"">Two</OPTION>"
Response.Write "</SELECT></TR></B>"
Response.Write "</FORM>" & Chr(13)
xy=Request.Querystring("select1")
Response.Write "<P><input type=""text"" id=""text1""
name=""text1""></P>" Response.Write "<P><input type=""button""
value=""ButtonX"" onclick=""text1.value='" & xy & "';""
METHOD=""get"" id=button1 name=button1></P>"

I click the button(ButtonX),but the testbox(text1) is none.
Can you more help me

You're doing too much response.write'ing. This is very hard to follow (and,
it must be hard to write). Nevertheless, some problems do reveal themselves:

1. METHOD is an attribute of a FORM element, not an INPUT element
2. You aren't telling the form where it should be submitted - use the FORM
element's ACTION attribute
3. You aren't submitting the form - you need to
a. have a Submit input element within the FORM, or
b. have your button input element's onclick event include code to submit
the form
4. You do not seem to understand when the xy variable will be populated.
When an asp page is called on the server, all server-side code is executed
before the resulting html is sent to the client. So, in your code, when the
asp page is called, the hetml that is sent to the client browser includes
this code (which you can verify by using View Source in your browser
window):
<input type="text" id="text1" name="text1">
<input type="button" value="ButtonX"" onclick="text1.value='';"
METHOD=""get"" id=button1 name=button1>

You see? When this button is clicked, it will set the text1.value to a blank
string. And nothing else will happen.

But let's suppose that you also included code to submit the form. Assuming
you've set the ACTION attribute to submit the form to itself, when you submi
t the page after select "Two" in the dropdown, and it reloads in the client
browser, the html source of the reloaded page will look like this:
<input type="text" id="text1" name="text1">
<input type="button" value="ButtonX"" onclick="text1.value='2';"
METHOD=""get"" id=button1 name=button1>

So, the textbox will still be blank ... until you click the button. But,
when you click the button, the form will be resubmitted, so the user will
never have a chance to see the new value of the textbox.


Here is what I would do (this code has been tested - give it a try):

<%
'This page is called ASPPage6.asp
option explicit
dim xy
xy=Request.Querystring("select1")
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM action="ASPPage6.asp" method=GET id=form1 name=form1>
<SELECT id=select1 name=select1>
<OPTION value="1">One</OPTION>
<OPTION value="2">Two</OPTION>
</SELECT>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
<P>
<INPUT type="text" id=text1 name=text1 value="<%=xy%>">
</P>
</FORM>
</BODY>
</HTML>

When the page initially loads in the browser, the textbox will be blank.
When you select an option from the dropdown and click the Submit button, the
page will reload and the textbox will contain the selected value

HTH,
Bob Barrows
 
L

London

Thank you very much.
but
I wrote this code:

<%@ Language=VBScript %>
<%
option explicit
dim xy
xy=Request.Querystring("select1")
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=x-sjis">
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<FORM id=form1 name=form1 action=ASPPage6.asp method=get>
<SELECT id=select1 name=select1>
<OPTION value=1 selected>One</OPTION>
<OPTION value=2>Two</OPTION>
</SELECT>
<P><INPUT id=submit1 type=submit value=Submit name=submit1></P>
<P><INPUT id=text1 value="<%=xy%>" name=text1></P>
</FORM>
</BODY>
</HTML>

When I click the submit button,the page is error.Error message:
"
Page not found
....
HTTP 404 - Files not found
Internet Information Services
....
"
Can you more help me
 
B

Bob Barrows

Ummmm - replace "ASPPage6.asp" with the actual name of the asp page???

By the war, I very deliberately surrounded the attribute values (such as
"ASPPage6.asp") with quotes in the example I provided. I do not see quotes
in your new code here.

Bob Barrows
 
S

SW

I have a similar task to "London's" and am having trouble finding the
easiest way to do it. I do have some asp experience but sometimes you
have to do new things...

I have built a form and have it submitting to the server fine. The
problem I am having is that in many text boxes I need to be able to go
"lookup" the value the user typed in and then populate another text
box with an answer (from another table).

Example:
The user is typing in a mechanical problem description. One field is
a "Part number" - when the user types that in and moves off that field
I have to go to another table with that part number and lookup the
"Description" of that part number, I then have to auto-fill that text
box on the screen. I can do it with a Submit button but the customer
wants this to happen automatically (!darn customers!) without having
to click on anything.

I have to use all VBScript because of customer requirements so I don't
think the OnBlur() attribute is available to me.

I thought I could put some VBScript lookup code in the 'value'
attribute of the "part number" field?? But I can't find any
examples of people doing this on any of these groups.

Anyone have some ideas or know where some examples of this might be?

Thanks for the help!

Susan Williamson
 
G

Guinness Mann

The user is typing in a mechanical problem description. One field is
a "Part number" - when the user types that in and moves off that field
I have to go to another table with that part number and lookup the
"Description" of that part number, I then have to auto-fill that text
box on the screen. I can do it with a Submit button but the customer
wants this to happen automatically (!darn customers!) without having
to click on anything.

Susan, I don't understand your problem well enough to answer your
question, but I do have a couple of comments.

First, this problem would be trivial in .NET. Perhaps that's not an
option for you.

Secondly, another group here at work has a sort of related situation.
What they do is bring an entire table of data over to the client along
with the form. Then as the user moves around on the form they use
javascript to update various fields. Note that our application runs on
an intranet, and we have complete control over browsers and settings.

-- Rick
 
J

janice li

I need help to display the selected value from database in the dropdown
list. Following is my code...but there are some error:

while NOT rs.EOF
Response.Write ("<option value = '" & rs("Description") & "'")
Response.Write (">")
If rs("Description") = rsStatus("sc_status") Then
Response.Write ("<Option value = '" & rsStatus("sc_status") & "'
SELECTED>")
Else
Response.Write (rs("Description"))
Response.Write ("</option>")
rsStatus.MoveNext
end if
wend
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top