Link to home
Start Free TrialLog in
Avatar of bburd
bburd

asked on

How to retrieve the selected record out of a table on client-side?

I display a table of products out of which you can select by checkboxes. You
can also give in the amount you want to order for every product.

So to order a product you have to mark the corresponding checkbox and give in the amount.

The selection someone makes is then put in a table.
The problem is that I can't store the amount right of the product someone has selected.
Is there a way to detect on the client-side which record is selected, because now,
when you select for example the third record, the amount of the first record is stored
in the table

Piece of the code:

<%        
function fncToevoegen()

for i=1 to request.form("check").count

 redim prodartID(i)
 redim prodarthoev(i)
 
  prodartID(i) = request.form("check")(i)
  prodarthoev(i) = request.form("quantity")(i)          

 if not prodartID(i) = "" then      

 sql="Select * from Artikels where Prod_art_ID= " & prodartID(i) & ""
 set rs5 = Server.CreateObject("ADODB.RecordSet")
 rs5.open sql, oconn, adOpenStatic,3
 prodartomschr = rs5("Prod_art_omschr")

 sqladd = "insert into Bestelling values ('" & prodartID(i) & "', '" & prodartomschr & "', '" & prodarthoev(i) & "')"
 oconn.execute(sqladd)
 end if    

next

end function
%>  
Avatar of gladxml
gladxml

bburd,

Kindly post the code with the checkbox...
ASKER CERTIFIED SOLUTION
Avatar of gladxml
gladxml

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To explain further by making the textfield name equal to the value of the checkbox...

Everytime that the checkbox is check you can also get the value of the textfield on the loop... By referring to the checkbox name...

Which is accomplish by this lines inside the loop..

tmpquantity = Request("check")(i)
response.write request.form(tmpquantity)    


Since you have the values that you need which is the quantity and the productid which im sure a unique one you can now update the database directly....

BTW you dont need to put the values in an array collection.

Note: all checkbox must have the same name..

You can refer to the link below regarding the concept of making the checkbox with the same name....

https://www.experts-exchange.com/questions/20450556/request-form-with-a-local-variable.html

Happy programming...
This query is incorrect:
sqladd = "insert into Bestelling values ('" & prodartID(i) & "', '" & prodartomschr & "', '" & prodarthoev(i) & "')"

It should read something like:
sqladd = "insert into Bestelling (column1, column2, column3) values ('" & prodartID(i) & "', '" & prodartomschr & "', '" & prodarthoev(i) & "')"

Where:
column1 = Field for "prodartID(i)"
column2 = Field for "prodartomschr"
column3 = Field for "prodarthoev(i)"

Hope that helps.

Regards,
Wakie.
Just another note, inside your For/Next loop you are redimming your arrays on each pass. The elements in these arrays are not getting preserved. You can try two methods:

Method 1:
<%
'...
redim prodartID(request.form("check").count)
redim prodarthoev(request.form("check").count)

for i=1 to request.form("check").count
'...
%>

Method 2:
<%
for i=1 to request.form("check").count

redim preserve prodartID(i)
redim preserve prodarthoev(i)
'..
%>

I would use the the first method, however it all depends which works for you. Cheers.

Wakie.
Avatar of bburd

ASKER

Thx,

it couldn't be easier!