Link to home
Start Free TrialLog in
Avatar of pcalabria
pcalabriaFlag for United States of America

asked on

ASP Checkbox Question: How do you retrieve values of a row?

Hello experts,

I have a table generated in HTML and ASP that I create on a webpage.
The table can have any number of rows.  
Each row includes a part number, quantity, and unit price.
The user selects the row(s) that he wants by checking a checkbox that appears at the end of each row.

The form is then submitted using a submit button setup to "get" a querystring to a page called MyPage.asp.

MyPage.asp simply needs to determine which part numbers, quantities, and prices were selected.

The problem that I am having is that when no checkbox is checked, nothing is sent in the querystring.  For example, if either "checked" or "not checked" was sent I could easily test each item in the collection using the index to find all the checked items, but this doesn't work because the items do not exist unless the checkbox is checked, thereby returning an out of range error.

There must be an easier way!

Can anyone help?
Avatar of Alfredo Luis Torres Serrano
Alfredo Luis Torres Serrano
Flag of United States of America image

I would use javascript to assign the checked values upon form submission to a hidden form variable in a comma delimited string, then when that data is passed to the server, you can parse that one variable and do what you need with it.
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

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
thats for .NET, not classic asp
which one is for .net? my code? asp or .Net does not make so much difference. Here is asp version:

dim rowsChecked
rowsChecked = Split(Request("rowChecked"),",")
for counter = 0 to UBound(rowsChecked)
    process(rowsChecked(counter)
next

Open in new window


The important thing here is the idea, not the implementation :)
Avatar of pcalabria

ASKER

Thanks All!
The solution presented by HainKurt provided me with the idea for a very simple resolution of this problem.  

I simply created a row counter variable, and then used this variable as the value for the checkbox.  

On the page that is called with the submit button is pressed the solution was to create a recordset of the checkbox name variable.  So if there were 10 rows on the form and two were selected, the recordset included two records, and the value of these two records provided the index reference for all the text boxes that were selected.

Thanks all for your contributions, and HainKurt thanks again for the idea.