...

View Full Version : Dynamically naming textboxes



Clarkey Boy
04-17-2006, 07:49 PM
Hi,

My situation is this:

I am creating a page for products. I have a product ID for each product in the database. I have a loop in which I have rows for a table - it creats one row per product and places the product information into its own row. I also have a text box in one cell for each product. I have named these text boxes as "<%=x%>" where x = rsproducts("productID") - so in effect each textbox is named as the ID of the product whose row it is in. I have stock and outgoing stock (products which have been sold) in the database. Now I would like to make it so that if someone puts a number in a textbox then it takes that number of products away from the stock value of the product with the same product ID as the textbox name.

Can anyone tell me how I can do this please? I have also got a variable y which is rsproducts("productID") and I am trying to work out how to get the value of each text box out as separate integers so that it gets taken away from the stock value of the correct product. Thats the bit I am stuck on - getting the name of the textbox correct as it is a variable.

The following code is what I am currently using in the page:



<table width="100%">
<tr>
<td>
<strong>
Products
</strong>
</td>
<td>
<strong>
Product ID
</strong>
</td>
<td>
<strong>
In Stock
</strong>
</td>
<td>
<strong>
Outgoing
</strong>
</td>
</tr>
<%
Do While not rsproducts.EOF
%>
<tr>
<td>
<%
Response.write(rsproducts("product"))
%>
</td>
<td>
<%
Response.write(rsproducts("productid"))
%>
</td>
<td>
<%
Response.write(rsproducts("stock"))
%>
</td>
<td>
<%
Response.write(rsproducts("outgoing"))
%>
</td>
<%
x = rsproducts("productid")
%>
<form action="adminorder.asp" method="get">
<td>
<input type="text" name="<%=x%>">
</td>
<td>
<%
Response.write("x = " & x)
%>
</td>
</tr>
<%
y = rsproducts("productID")
y = "0001"
rsproducts("stock") = rsproducts("stock") - request.form(y)
rsproducts.update
rsproducts.movenext
loop
%>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<input type="submit" name="submit">
</td>
</form>
</table>
<form action="adminorder.asp" method="post">
<table width="50%">
<tr>
<td>
Product:
</td>
<td>
<input type="text" name="product">
</td>
</tr>
<tr>
<td>
Product ID:
</td>
<td>
<input type="text" name="productid">
</td>
</tr>
<tr>
<td>
Stock:
</td>
<td>
<input type="text" name="stock">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="Submit" name="submit">
</td>
</tr>
</table>
<%
product = request.form("product")
productid = request.form("productid")
stock = request.form("stock")
If product = "" then
Else
If productid = "" then
Else
If stock = "" then
Else
rsproducts.addnew
rsproducts("product") = product
rsproducts("productid") = productid
rsproducts("stock") = stock
rsproducts.update
response.redirect("adminorder.asp")
End If
End If
End if
%>

degsy
04-18-2006, 03:49 PM
You would have to have the id/name of the textbox as the id of the product, or atleast containing it.


When you submit the form the textbox

e.g. This code will extract the ID and the quantity entered


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<%
If Len(Request.Form) > 0 Then
For Each Item In Request.Form
If InStr(Item, "id_") AND Len(Request.Form(Item)) > 0 Then
id = Split(Item, "id_")
Response.Write id(1) & ": " & Request.Form(Item) & "<br>"
End If
Next
End If
%>
<form name="form1" method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="2">
<%For x=0 To 3%>
<tr>
<td><%=x%></td>
<td>5</td>
<td>product_<%=x%></td>
<td><input type="text" name="id_<%=x%>"></td>
</tr>
<%Next%>
</table>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

Clarkey Boy
04-19-2006, 01:03 AM
If Len(Request.Form) > 0 Then
For Each Item In Request.Form
If InStr(Item, "id_") AND Len(Request.Form(Item)) > 0 Then
id = Split(Item, "id_")
Response.Write id(1) & ": " & Request.Form(Item) & "<br>"
End If
Next
End If


Well I got SOMEWHERE with that code - but where I just do not know... Dreamweaver, for some reason, won't accept the ">" symbols - so I changed it to "if... ...<= 0 Then
Else..."

When I used > it just blanked out the code (would not read it as ASP). Is there any solution to this other than having to use an if statement and changing the > to <= and using "else"? Also, I don't know exactly how to apply this to my code.

RC

degsy
04-19-2006, 02:58 PM
Dreamweaver has no problem with the code. it was written in dreamweaver.

You probably have an error somwehere else in your code.

Clarkey Boy
04-19-2006, 04:43 PM
Well I am gonna leave that page for a while and try to recreate the page using PHP - I am pretty sure I know how to do this in PHP, but will try it out over the next day or two and put a message here saying whether I have successfully done it or not.

RC



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum