Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > How to pass a code of a list box to a processing form

Reply
Thread Tools

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

 
 
Jack
Guest
Posts: n/a
 
      03-01-2006
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.




 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      03-01-2006
Jack wrote:
> 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:

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


> 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.

--
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.


 
Reply With Quote
 
 
 
 
Jack
Guest
Posts: n/a
 
      03-02-2006
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")& "'>"


"Bob Barrows [MVP]" wrote:

> Jack wrote:
> > 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:
>
> Response.Write "<Option Value='" & RS_Year("YEARID")& "'>"
>
>
> > 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.
>
> --
> 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.
>
>
>

 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      03-02-2006
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>



"Jack" wrote:

> 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")& "'>"
>
>
> "Bob Barrows [MVP]" wrote:
>
> > Jack wrote:
> > > 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:
> >
> > Response.Write "<Option Value='" & RS_Year("YEARID")& "'>"
> >
> >
> > > 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.
> >
> > --
> > 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.
> >
> >
> >

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      03-02-2006
Jack wrote:
> 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.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Bob Lehmann
Guest
Posts: n/a
 
      03-02-2006
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

"Jack" <> wrote in message
news4C0BC42-583B-4F51-8A8A-...
> 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")& "'>"
>
>
> "Bob Barrows [MVP]" wrote:
>
> > Jack wrote:
> > > 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:
> >
> > Response.Write "<Option Value='" & RS_Year("YEARID")& "'>"
> >
> >
> > > 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.
> >
> > --
> > 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.
> >
> >
> >



 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      03-02-2006
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.

"Bob Barrows [MVP]" wrote:

> Jack wrote:
> > 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.
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>
>

 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      03-02-2006
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

"Bob Lehmann" wrote:

> 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
>
> "Jack" <> wrote in message
> news4C0BC42-583B-4F51-8A8A-...
> > 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")& "'>"
> >
> >
> > "Bob Barrows [MVP]" wrote:
> >
> > > Jack wrote:
> > > > 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:
> > >
> > > Response.Write "<Option Value='" & RS_Year("YEARID")& "'>"
> > >
> > >
> > > > 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.
> > >
> > > --
> > > 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.
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Mike Brind
Guest
Posts: n/a
 
      03-02-2006

Jack wrote:
> 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.

--
Mike Brind

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      03-02-2006
Jack wrote:
> 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>

--
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
how to pass selected item from listbox of one form to text box of other form chintan Software 0 12-19-2007 11:38 AM
pass conventional html upload form to asp.net page for processing Jon Paal ASP .Net 0 09-27-2006 07:08 PM
populate one list box with selected values from another list box steven.cooper@infocision.com ASP .Net 1 03-12-2005 11:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57