Radio Buttons - Populating

Discussion in 'ASP General' started by Suzanne, Aug 14, 2003.

  1. Suzanne

    Suzanne Guest

    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
     
    Suzanne, Aug 14, 2003
    #1
    1. Advertising

  2. Suzanne

    Mike Guest

    "Suzanne" <> wrote in message
    news:114001c36277$66d4acb0$...
    > 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.

    --
    Mike
     
    Mike, Aug 14, 2003
    #2
    1. Advertising

  3. 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




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Suzanne Murray, Aug 16, 2003
    #3
  4. Suzanne

    Alan Guest

    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


    "Suzanne" <> wrote in message
    news:114001c36277$66d4acb0$...
    > 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
     
    Alan, Aug 16, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott D Johnson
    Replies:
    1
    Views:
    1,075
    Scott D Johnson
    Sep 27, 2006
  2. Jan C. Faerber
    Replies:
    0
    Views:
    622
    Jan C. Faerber
    Jun 30, 2009
  3. Hiten
    Replies:
    1
    Views:
    625
    Vidar Petursson
    May 26, 2004
  4. Dr. Leff
    Replies:
    3
    Views:
    299
    David Mark
    Oct 15, 2007
  5. Dr. Leff
    Replies:
    3
    Views:
    230
    David Mark
    Oct 15, 2007
Loading...

Share This Page