Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update fields in a database through dynamic controls

Status
Not open for further replies.

mihalych

Programmer
Jul 24, 2003
27
US
Could somebody help me with the following problem. When I select a particular equipment, the catalogue containing products is dynamically generated. The products belong to that particular equipment. The code for that is :

<%Do while not rsProduct.EOF%>
<TR><TD><IMG SRC=<%=rsProduct(&quot;ImageURL&quot;)%> width=100 height=90></TD>
<TD><% =rsProduct(&quot;ProductName&quot;)%></TD>
<TD><% =rsProduct(&quot;Price&quot;)%></TD>
<TD><% =rsProduct(&quot;Description&quot;)%></TD>
<TD><INPUT type=&quot;text&quot; size=2 id=text1 name=&quot;<%=rsProduct(&quot;ProductCode&quot;)%>&quot;>&nbsp;<INPUT type=&quot;button&quot; value=&quot;Add&quot; id=&quot;<%=rsProduct(&quot;ProductCode&quot;)%>&quot; name=&quot;<%=rsProduct(&quot;ProductCode&quot;)%>&quot;TD>
</TR>
<%rsProduct.MoveNext%>
<%Loop%>
It works well. It also generates text boxes and buttons next to each product to update quantity for any product into a database. My question is how to write procedure for that buttons to update quantity as they are generated by server-side scripts dynamically. How can I access properties of the text boxes?
Something like:
<% For Each objItem in Request.Form…etc……

But I have to update quantity for a particular product code in a database associated with particular textbox. How to refer to a particular name of the textbox in server-side script?
 
I'm assuming that your buttons submit the form to a pages that does the processing? Something like this should work:

First, add some characters to the name attribute of the text boxes like:
name=&quot;txt<%=rsProduct(&quot;ProductCode&quot;)%>&quot;

On the processing form:
For each objItem in request.form()
If left(objItem,3) = &quot;txt&quot; Then
If request.form(objItem) <> &quot;&quot; then 'just the ones with values
myProductCode = mid(objItem,4)
myQuantity = request.form(objItem)
strSql=&quot;UPDATE MyTable SET Quantity =&quot; & myQuantity & _
&quot; WHERE ProductCode='&quot; & myProductCode & &quot;'&quot;
conn.execute(strSql)
End IF
End IF
NEXT

Note: I made the assumption that your product code is a string. If not you'll have the make the necessary change to the SQL statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top