|
 |
asp_databases thread: Can I reference dynamically created DTC's i.e. text box values?
Message #1 by "Jeff Ball" <jeff@t...> on Wed, 20 Jun 2001 19:50:12
|
|
Hi
I am trying to build a product list from a SQL database, which contains a
text box for quantity to be ordered. I can generate the ASP page with all
the information I need including the text box. When I try to add an item
to my ASP cart page I get an Error
?txt? variable is undefined. Any help is greatly appreciated.
Is it possible to dynamically build a list of items including DTC
controls, and then reference the values after the page has been generated,
or am I out of my mind?
Thanks in advance
do while not objRecProducts.eof
' draw the name item
Response.Write "<tr><td>"
Response.Write objRecProducts("ProductName")
Response.Write "</td><td align=center>"
Response.Write objRecProducts("UnitsPerCase")
Response.Write "</td><td>"
Response.Write "<INPUT name=txt value=" & request("Qty")
& ">"
Response.Write "</td><td>"
Response.Write "<a href=""ProductDetails.asp?ProdID=" &
objRecProducts("ProductID") & """>"
Response.Write "Details"
Response.Write "</a>"
Response.Write "</td><td>"
Response.Write "<a href=""cart.asp?ProdID=" &
objRecProducts("ProductID") & "Qty=" & txt.value & """>"
Response.Write "Order"
Response.Write "</a>"
' finish the row
Response.Write "</td></tr>"
' next
objRecProducts.movenext
Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Wed, 20 Jun 2001 15:18:54 -0400
|
|
Jeff,
It looks like you are trying to reference txt.value, which at that
point
does not exist. Instead, you could try doing the same thing you did to
create the txt input box. That is:
Response.Write "<a href=3D""cart.asp?ProdID=3D" &
objRecProducts("ProductID") & "Qty=3D" & request("Qty") & """>"
However, there are other errors with your code as well. Assuming
objRecProducts("ProductID") =3D 5 and request("Qty") =3D 9, your
generated
code would look like this:
<a href=3D"cart.asp?ProdID=3D5Qty=3D9">
Note that you have not delimited the items in your querystring. You
need to modify it like so:
Response.Write "<a href=3D""cart.asp?ProdID=3D" &
objRecProducts("ProductID") & "&Qty=3D" & request("Qty") & """>"
to produce:
<a href=3D"cart.asp?ProdID=3D5&Qty=3D9">
Which, when clicked, is interpreted by the browser as:
cart.asp?ProdID=3D5&Qty=3D9
Also, some of your attributes lack quotes around their values. I
recommend using them (in case you ever want to write your pages as
XHTML).
Good luck,
Pete
> -----Original Message-----
> From: Jeff Ball [mailto:jeff@t...]
> Sent: Wednesday, June 20, 2001 7:50 PM
> To: ASP Databases
> Subject: [asp_databases] Can I reference dynamically created
> DTC's i.e.
> text box values?
>
>
> Hi
> I am trying to build a product list from a SQL database,
> which contains a
> text box for quantity to be ordered. I can generate the ASP
> page with all
> the information I need including the text box. When I try to
> add an item
> to my ASP cart page I get an Error
> "txt" variable is undefined. Any help is greatly appreciated.
>
> Is it possible to dynamically build a list of items including DTC
> controls, and then reference the values after the page has
> been generated,
> or am I out of my mind?
>
> Thanks in advance
>
> do while not objRecProducts.eof
> ' draw the name item
> Response.Write "<tr><td>"
> Response.Write objRecProducts("ProductName")
> Response.Write "</td><td align=3Dcenter>"
> Response.Write objRecProducts("UnitsPerCase")
> Response.Write "</td><td>"
> Response.Write "<INPUT name=3Dtxt value=3D" & request("Qty")
> & ">"
> Response.Write "</td><td>"
> Response.Write "<a href=3D""ProductDetails.asp?ProdID=3D" &
> objRecProducts("ProductID") & """>"
> Response.Write "Details"
> Response.Write "</a>"
> Response.Write "</td><td>"
> Response.Write "<a href=3D""cart.asp?ProdID=3D" &
> objRecProducts("ProductID") & "Qty=3D" & txt.value & """>"
> Response.Write "Order"
> Response.Write "</a>"
> ' finish the row
> Response.Write "</td></tr>" =09
> ' next =09
> objRecProducts.movenext
Message #3 by Jeffrey Ball <jeff@t...> on Wed, 20 Jun 2001 16:38:42 -0500
|
|
Pete,
Thanks for your help. I made your suggested changes to my code, however I
am still not loading data into "Qty". What can I do to check the value of
the textbox value before it is sent as a Querystring.
Here is what I have.
Thanks again.
Jeff
set objrecproducts = db.GetProductInCat(request("catid"))
if not objRecProducts.eof then
' loop the products view
do while not objRecProducts.eof
' draw the name item
Response.Write "<tr><td>"
Response.Write objRecProducts("ProductName")
Response.Write "</td><td align=center>"
Response.Write objRecProducts("UnitsPerCase")
Response.Write "</td><td>"
Response.Write "<INPUT name=txt" &
objRecProducts("ProductID") & request("Qty") & ">"
Response.Write "</td><td>"
Response.Write "<a href=""ProductDetails.asp?ProdID=" &
objRecProducts("ProductID") & """>"
Response.Write "Details"
Response.Write "</a>"
Response.Write "</td><td>"
Response.Write "<a href=""cart.asp?ProdID=" &
objRecProducts("ProductID") & "&Qty=" & request("Qty") & """>"
Response.Write "Order"
Response.Write "</a>"
' finish the row
Response.Write "</td></tr>"
' next
objRecProducts.movenext
-----Original Message-----
From: Peter Foti (PeterF) [mailto:PeterF@S...]
Sent: Wednesday, June 20, 2001 2:19 PM
To: ASP Databases
Subject: [asp_databases] RE: Can I reference dynamically created DTC's
i.e . text box values?
Jeff,
It looks like you are trying to reference txt.value, which at that point
does not exist. Instead, you could try doing the same thing you did to
create the txt input box. That is:
Response.Write "<a href=""cart.asp?ProdID=" &
objRecProducts("ProductID") & "Qty=" & request("Qty") & """>"
However, there are other errors with your code as well. Assuming
objRecProducts("ProductID") = 5 and request("Qty") = 9, your generated
code would look like this:
<a href="cart.asp?ProdID=5Qty=9">
Note that you have not delimited the items in your querystring. You
need to modify it like so:
Response.Write "<a href=""cart.asp?ProdID=" &
objRecProducts("ProductID") & "&Qty=" & request("Qty") & """>"
to produce:
<a href="cart.asp?ProdID=5&Qty=9">
Which, when clicked, is interpreted by the browser as:
cart.asp?ProdID=5&Qty=9
Also, some of your attributes lack quotes around their values. I
recommend using them (in case you ever want to write your pages as
XHTML).
Good luck,
Pete
> -----Original Message-----
> From: Jeff Ball [mailto:jeff@t...]
> Sent: Wednesday, June 20, 2001 7:50 PM
> To: ASP Databases
> Subject: [asp_databases] Can I reference dynamically created
> DTC's i.e.
> text box values?
>
>
> Hi
> I am trying to build a product list from a SQL database,
> which contains a
> text box for quantity to be ordered. I can generate the ASP
> page with all
> the information I need including the text box. When I try to
> add an item
> to my ASP cart page I get an Error
> "txt" variable is undefined. Any help is greatly appreciated.
>
> Is it possible to dynamically build a list of items including DTC
> controls, and then reference the values after the page has
> been generated,
> or am I out of my mind?
>
> Thanks in advance
>
> do while not objRecProducts.eof
> ' draw the name item
> Response.Write "<tr><td>"
> Response.Write objRecProducts("ProductName")
> Response.Write "</td><td align=center>"
> Response.Write objRecProducts("UnitsPerCase")
> Response.Write "</td><td>"
> Response.Write "<INPUT name=txt value=" & request("Qty")
> & ">"
> Response.Write "</td><td>"
> Response.Write "<a href=""ProductDetails.asp?ProdID=" &
> objRecProducts("ProductID") & """>"
> Response.Write "Details"
> Response.Write "</a>"
> Response.Write "</td><td>"
> Response.Write "<a href=""cart.asp?ProdID=" &
> objRecProducts("ProductID") & "Qty=" & txt.value & """>"
> Response.Write "Order"
> Response.Write "</a>"
> ' finish the row
> Response.Write "</td></tr>"
> ' next
> objRecProducts.movenext
Message #4 by "Peter Foti (PeterF)" <PeterF@S...> on Thu, 21 Jun 2001 11:42:49 -0400
|
|
Hi Jeff,
Without seeing the whole file, it's hard to troubleshoot, but I'll take
a stab at it anyway. :)
Try this... for debugging, put a line in there that says:
Response.write("<b>" & request("Qty") & "</b>")
We want to make sure that request("Qty") actually has a value, so we'll
print it to the screen for now.
Now, looking more closely at your code, it seems that the output would
look like this (for the input box):
<INPUT name=txt3951>
This is because you have the ProductID and Qty all assigned to name
attribute. Perhaps you meant to have the productID as part of the name,
but I can't imagine the Qty is supposed to be part of the name. Did you
want something more like this:
<INPUT name='txt395' value='1'>
The next thing we want to do is make sure all the attributes are quoted.
Especially the ones that are getting this value. So lets do a little
cleanup. Lets add parenthesis to all the Response.Write statements.
And lets take care of those unquoted attributes. I'll use single quotes
because they are easy and work the same as double quotes (vs. trying to
escape double quotes... I find it makes it harder to read). While we're
at it, we might as well Server.URLEncode the values in the query string
in the <a> tag... it's a good habit to get into to make sure that an
invalid link will never be created by, say, a query string value having
a space in it or something. And might as well do Server.HTMLEncode on
the other text so as to avoid problems with ProductName containing a <
or something. It's probably overly redundant, but better to be safe
than sorry. But first, get rid of the "if not objRecProducts.eof then"
at the beginning. The reason I say to get rid of it is because this is
handled by the "do while" statement. If you have this here to handle an
"else" condition, then change your code to look like this:
set objrecproducts = db.GetProductInCat(request("catid"))
if objRecProducts.eof then
' Put your else case here
end if
' loop the products view
do while not objRecProducts.eof
' draw the name item
Response.Write( "<tr><td>" )
Response.Write( Server.HTMLEncode( objRecProducts("ProductName")
) )
Response.Write( "</td><td align='center'>" )
Response.Write( Server.HTMLEncode(
objRecProducts("UnitsPerCase") ) )
Response.Write( "</td><td>" )
Response.Write( "<INPUT name='txt" & Server.HTMLEncode(
objRecProducts("ProductID") ) & "' value='" & Server.HTMLEncode(
request("Qty") ) & "'>" )
Response.Write( "</td><td>" )
Response.Write( "<a href=""ProductDetails.asp?ProdID=" &
Server.URLEncode( objRecProducts("ProductID") ) & """>" )
Response.Write( "Details" )
Response.Write( "</a>" )
Response.Write( "</td><td>" )
Response.Write( "<a href=""cart.asp?ProdID=" & Server.URLEncode(
objRecProducts("ProductID") )& "&Qty=" & Server.URLEncode(
request("Qty") ) & """>")
Response.Write( "Order" )
Response.Write( "</a>" )
' finish the row
Response.Write( "</td></tr>" )
' next
objRecProducts.movenext
Loop
On a side note, this code is all executed server side. So this should
spit out an input box with a Qty in it and a link with the Qty in it.
However, if the client changes the value in the input box, it will not
change the Qty that is sent with the Order link. That's probably NOT
the behavior you want. You might consider changing this to a form, and
checking the quantity on your cart page. Unfortunately, since you are
using tables for page layout (that's a No-No), this is not easily
accomplished. However, if you wanted to keep the layout in tables, then
you might add another layer to that each ROW contained a table. Like
so...
set objrecproducts = db.GetProductInCat(request("catid"))
if objRecProducts.eof then
' Put your else case here
end if
' loop the products view
do while not objRecProducts.eof
' draw the name item
Response.Write( "<tr><td>" )
Response.Write( "<form action='cart.asp' method='post'>" )
Response.Write( "<table width='100%'><tr><td>" )
Response.Write( Server.HTMLEncode( objRecProducts("ProductName")
) )
Response.Write( "<input type='hidden' name='ProdID' value='" &
Server.HTMLEncode( objRecProducts("ProductID") ) & "'>" )
Response.Write( "</td><td align='center'>" )
Response.Write( Server.HTMLEncode(
objRecProducts("UnitsPerCase") ) )
Response.Write( "</td><td>" )
Response.Write( "<INPUT name='Qty' value='" & Server.HTMLEncode(
request("Qty") ) & "'>" )
Response.Write( "</td><td>" )
Response.Write( "<a href=""ProductDetails.asp?ProdID=" &
Server.URLEncode( objRecProducts("ProductID") ) & """>" )
Response.Write( "Details" )
Response.Write( "</a>" )
Response.Write( "</td><td>" )
Response.Write( "<input type='submit' value='Order'
name='Prod'>" )
' finish the row
Response.Write( "</td></tr></table>" )
Response.Write( "</form>" )
Response.Write( "</td></tr>" )
' next
objRecProducts.movenext
Loop
Then, on your cart.asp page, you will need to look at the 2 inputs,
ProdID and Qty.
Hope this helps!
Regards,
Peter
|
|
 |