Radio Buttons - Populating

S

Suzanne

Hi,

I have a form which our clients can fill in with their
personal details. As part of the information we store
there is a section - areas of interest - this is a number
of radio buttons.

I need to be able to send to a stored procedure the areas
that the client has selected so these can be stored in the
database.
And I need to receive these values so I can display to the
user their selected options when they return to the page.

I'm not too sure what way to approach this and would be
greatful of some advice.

Here are the options I have been considering:

1)Passing the client ID and then the options as a series
of 0's and 1's (in one record)
2) Passing the client ID and then the numbers of the radio
buttons selected (in one record)
3) Passing the client ID and a number of a radio button
selected in separate records (ie. the total number of
records would match the total number of options selected)

I know I have probably not explained this very well, but I
would apprechiate some advise on the best way to deal with
this.

Thanks
Suzanne
 
M

Mike

Suzanne said:
Hi,

I have a form which our clients can fill in with their
personal details. As part of the information we store
there is a section - areas of interest - this is a number
of radio buttons.

I need to be able to send to a stored procedure the areas
that the client has selected so these can be stored in the
database.
And I need to receive these values so I can display to the
user their selected options when they return to the page.

I'm not too sure what way to approach this and would be
greatful of some advice.

Here are the options I have been considering:

1)Passing the client ID and then the options as a series
of 0's and 1's (in one record)
2) Passing the client ID and then the numbers of the radio
buttons selected (in one record)
3) Passing the client ID and a number of a radio button
selected in separate records (ie. the total number of
records would match the total number of options selected)

Are you passing the info to a database and then pulling it back out each
time the user returns to a page? Sounds like it, but if I'm wrong sorry. :)

I'd have a record containing the id for each client and separate Boolean
fields for each option. Using a series of 0's and 1's will cause major
issues if you ever change your options (adding, removing, reordering, etc.).
Same thing with a single field that contains special identifiers for each
option.
 
S

Suzanne Murray

Yes Mike, I am passing the data to the database and then returning it
when the user accesses the page.

Sorry I didn't explain that very well, I did mean to have the O's and
1's in separate fields for each option!
So you think this is the best option?

Thanks
Suzy
 
A

Alan

Hi there,

Trying to get my head around what you're doing - if a user can select
multiple interest-areas then perhaps checkboxes and not option buttons
(which are traditionally mutually exclusive) would be better on the UI.
Either way - the process is similar.

Each radio button/checkbox has the same name, AreaIDs for example (I always
use the plural of the entity), and the value is set to the database ID of
the record they're selecting. The ClientID can be posted through as a hidden
(or whatever).

In your processor you'll get the ClientID, Request.Form("ClientID"), and
you'll get the list of areas selected, Request.Form("AreaIDs"). This last
bit will return zero, one or more values. If 'more', then they'll be
formatted as a comma-separated list.

You have a couple of options now. I'm assuming you have a ClientInterests
associative table in your database to model the M:N mapping between clients
and interest areas. Because they may has also removed interests it's easier
to dump the current contents of this table for the given ClientID and then
insert the records in your list. Whether you put this in a SP in your ASP is
up to you, I'd probably do the latter - I'd probably already have a SP to do
an insert of one ClientInterest so another SP to process a list like this
would add duplication for not much benefit.

So, in your ASP/SP start by deleting records in the ClientInterests table
with that ClientID, and then iterate through your list with FOR...EACH after
SPLITting it and do an insert for each selected InterestID. In an SP, if you
take that approach, you'll pass the list though as it is (passed as
@InterestIDs below), delete the ClientInterest records for that ClientID
(passed as @ClientID below) and then do an INSERT using your list -
something like this:

INSERT INTO ClientInterests (ClientID, InterestID)
SELECT
@ClientID,
i.InterestID
FROM Interests i
WHERE i.InterestID IN (@InterestIDs)

Remember to trap an empty list or Interest IDs.

I've specifically not mentioned retrieving and displaying the selected
Interests for a Client - the other part of your post - because it is a
separate event - nothing to do with inserting/deleting the values. In a
nutshell, when your Client Details form loads, create an array from a
recordset (use GetRows) that contains the selected InterestIDs for that
Client (from the ClientInterests table) and as you're displaying each option
(from the Interests table) check to see if its ID is in there. If it is then
Response.Write 'checked' for your option or checkbox to make it display
selected by default.

This is a basic approach, a better one is to modify your SP/query to do an
outer join to the ClientInterests table for a specific ClientID while you're
generating your list of all Interests for display, and set a bit column to 1
or 0 (use CASE) if that client selected that interest. This way you need
only one RS and eliminate the need to keep doing nasty linear searches
through your array of selected IDs to see if each Interest ID is in there.

This is probably more detail than you wanted but see how you go - I'm off to
grab some breakfast.

Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top