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:
Code:
<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
%>