How to pass a code of a list box to a processing form

J

Jack

Hi,
I have a asp form where one element is a list box which lists four years
starting from 2004. This list is drawn from a database table which has YearID
and Year as two fields as shown below:
YearID YEAR
1 2004
2 2005
3 2006
4 2007
PART OF ASP CODE IS:

<tr>
<td width="74%" align ="center" height="18"><font face="Times New Roman"
size="3" color = "red">YEAR</font></td>
<td>
<SELECT NAME="lstYear" SIZE="1">

<% Do while not RS_Year.EOF
Response.Write "<Option Value='" & RS_Year("YEAR")& "'>"
Response.Write RS_Year("YEAR") & "</OPTION>"
RS_Year.MoveNext
Loop
%>
<td>
<tr>

Now I want to capture the value of the YearCode instead of the Year field
and store the year code value in the processing form to process in a sql
statement.

i.e. I am planning to use the Request.Form("lstYear") to capture the value
of the year code. However, Request.Form("listYear") is showing no value.
I would appreciate any help or any article link for handling this problem.
Thank in advance.
 
B

Bob Barrows [MVP]

Jack said:
Hi,
I have a asp form where one element is a list box which lists four
years starting from 2004. This list is drawn from a database table
which has YearID and Year as two fields as shown below:
YearID YEAR
1 2004
2 2005
3 2006
4 2007
PART OF ASP CODE IS:

<tr>
<td width="74%" align ="center" height="18"><font face="Times New
Roman" size="3" color = "red">YEAR</font></td>
<td>
<SELECT NAME="lstYear" SIZE="1">

<% Do while not RS_Year.EOF
Response.Write "<Option Value='" & RS_Year("YEAR")& "'>"
Response.Write RS_Year("YEAR") & "</OPTION>"
RS_Year.MoveNext
Loop
%>
<td>
<tr>

Now I want to capture the value of the YearCode instead of the

So why are you using RS_Year("YEAR") for the option value? Wouldn't it make
more sense to change it to:

Year field and store the year code value in the processing form to
process in a sql statement.

i.e. I am planning to use the Request.Form("lstYear") to capture the
value of the year code. However, Request.Form("listYear") is showing
no value.

At what point in the process? After you submitted form containing the above
SELECT element?

Create a small test form that reproduces the problem and post the entire
code from that SMALL test form.
 
J

Jack

Thanks Bob for your help. I am going to do that. However, the reason I am using
RS_Year("YEAR") for the option value is that I want to display all the YEAR
values in the the list box on the form. However, instead of Year I need to
capture the value of the corresponding code of the YEAR. This code goes to
the sql statement in the processing asp page. Thanks.

Response.Write "<Option Value='" & RS_Year("YEARID")& "'>"
 
J

Jack

Well Bob, I just trimmed my code to get a test asp page. Here please note
that the tblYear has YearId and Year field. I need to display the Year Value,
yet capture the YearId(ie. the selected one from the list box) in the
processing form using request object. This YearId will go the sql statement
in the processing form.This is the main issue to me ie. how to display one
field in the list box yet capture the corresponding ID from the form in the
processing asp page using request form object. Hope I could explain well.
Here is the code for the test page. Thanks. Regards,

<!-- #include file="connection.asp" -->
<!-- #include file="adovbs.inc" -->

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>

<center>
<h2>
<b>
<font size="5" color="navy">
TEST
</font>
</b>
</h2>
</center>

<BODY>




<%
Set RS_Year = Server.CreateObject("ADODB.Recordset")



strSQL3 = "SELECT YearId, Year FROM tblYear"
RS_Year.Open strSQL3, conn

%>
<form method=POST name="frm_mainentry" action="mainentry_process.asp"
onSubmit>
<div align="center">
<table border = "1" width="80%" height="1" cellspacing = "1">


<tr>
<td width="50%" align ="center" height="18"><font face="Times New Roman"
size="3" color = "red">COUNT TOTAL OFFENSES</font></td>
<td width="50%" align="center" BGCOLOR="white" height="18"><font
face="Times New Roman" size="1">
<input type="text" name="txt_CountTotalOffenses" size="57"
style="font-family: Times New Roman; font-size: 12pt"></font></td>
</tr>
<%'Response.End%>

<tr>
<td width="74%" align ="center" height="18"><font face="Times New Roman"
size="3" color = "red">YEAR</font></td>
<td>
<SELECT NAME="lstYear" SIZE="1">

<% Do while not RS_Year.EOF
Response.Write "<Option Value='" & RS_Year("YEAR")& "'>"
Response.Write RS_Year("YEAR") & "</OPTION>"
RS_Year.MoveNext
Loop
%>
<td>
<tr>
<%'Response.End%>

<tr>
<td width="100%" align="right" colspan = "2" height="27"><p><input
type="submit" value="Submit" name="B3"></td>
</tr>

</table>
</div>
</form>

</BODY>
</HTML>
 
B

Bob Barrows [MVP]

Jack said:
Thanks Bob for your help. I am going to do that. However, the reason
I am using RS_Year("YEAR") for the option value is that I want to
display all the YEAR values in the the list box on the form.

The Value is not displayed, the text is. Try it.
 
B

Bob Lehmann

I'm curious.

Since each year only happens once, why do you have a yearID column? I'm not
even really sure why you have a year table to begin with.

Unless you know something......

Bob Lehmann
 
J

Jack

Bob, Actually I meant the text Year is displayed which is fine. The user need
to click on the Year (e.g. 2004) to choose from the list. However, as I
pointed out earlier that though 2004 is click I need to capture the
corresponding YearID which is 1 in the present case (i.e. the year 2004 is
chosen). Hope I am more clear now. I have got the sample code here. Any
thoughts.
 
J

Jack

OK,
this is just a test. In reality this is a much bigger data entry form where
various parties will enter 2004 and 2005 data via the web application. The
Year list box helps them to have their choice instead of typing the value in.
In the final table where all the data is collected the YearID is collected
rather than the YEAR text. Hope I am little more clear. Thanks
 
M

Mike Brind

Jack said:
OK,
this is just a test. In reality this is a much bigger data entry form where
various parties will enter 2004 and 2005 data via the web application. The
Year list box helps them to have their choice instead of typing the value in.
In the final table where all the data is collected the YearID is collected
rather than the YEAR text. Hope I am little more clear. Thanks

As Bob has already pointed out a couple of times, with a Select list,
the value is passed with the form or querystring collection. So this:

<option value="somevalue">Some Text</option>

will display "Some Text" on the screen, but if it is selected, will
pass "somevalue" to the collection. The only time "Some Text" will be
passed is if you either leave the option value blank, or explicitly
define the value as "Some Text". The latter is in effect what you are
doing with RS("Year").

Consequently, Bob's code will work in exactly the way you want it to.
Try the test as he suggested.
 
B

Bob Barrows [MVP]

Jack said:
Well Bob, I just trimmed my code to get a test asp page.

:)
Obviously, you and i have different ideas about what constitutes a "small"
test page ;-)
Here please
note that the tblYear has YearId and Year field. I need to display
the Year Value, yet capture the YearId(ie. the selected one from the
list box) in the processing form using request object. This YearId
will go the sql statement in the processing form.This is the main
issue to me ie. how to display one field in the list box yet capture
the corresponding ID from the form in the processing asp page using
request form object. Hope I could explain well. Here is the code for
the test page. Thanks. Regards,

This is why I told you to set the value attribut to the YearID instead of
the Year. here, try this to see:


<!-- #include file="connection.asp" -->
<!-- #include file="adovbs.inc" -->
<%
strSQL3 = "SELECT YearId, Year FROM tblYear"
Set RS_Year =conn.execute(strsql3,,1)
if not rs_year.eof then arData=rs_year.getrows
rs_year.close:set rs_year=nothing
conn.close: set conn=nothing
sHTML=""
if isarray(ardata) then
for i = 0 to ubound(ardata,2)
shtml = shtml & "<option value = """ & _
ardata(0,i) & """>" & ardata(1,i) & "</option>"
next
end if
if len(request.form("lstYear")) > 0 then
response.write "The value of the option you selected is """ & _
request.form("lstYear")
end if
%>
<html><body><form method=POST >
<SELECT NAME= "lstYear" SIZE="1">
<%=shtml%>
</SELECT>
<input type="submit" value="Submit" >
</form></body></html>
 
J

Jack

This is a message for Bob.
I am still not clear about the whole thing yert. Bob, I have posted the code
using small test asp page as per your advise. Could you please let me know in
the test code what exactly is wrong? Can you show me couple of lines of code
in the test code to capture the chosen year (actually to capture yeardID)
using request.form. Thanks.
 
B

Bob Barrows [MVP]

Jack, did you try the test page i posted?
This is a message for Bob.
I am still not clear about the whole thing yert. Bob, I have posted
the code using small test asp page as per your advise. Could you
please let me know in the test code what exactly is wrong? Can you
show me couple of lines of code in the test code to capture the
chosen year (actually to capture yeardID) using request.form. Thanks.
 
J

Jack

Sorry Bob,
I overlooked the code you posted. I apologize for it. I am going to try
it.Regards.
 
J

Jack

Hi Bob,
I tried your code and it works now. Thanks a lot for the generous help. Best
regards.
 
B

Bob Barrows [MVP]

I guess the key question now is: do you understand why it works when your
original didn't?
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top