Pass Multiple Checkbox Values

Discussion in 'HTML' started by Marc, Feb 3, 2005.

  1. Marc

    Marc Guest

    Hi people, I have an idea I'm sure has been thought of before but I'm
    not sure how to execute. I'm using PHP and HTMl and am thinking that
    there must be an easy way to do this.

    I want to have one varchar or text field hold the value of several
    checkbox items as one string. For example, let's say I have 10 movies
    and want to list them in a string for the person to state their top 3.
    So if they check boxes 3, 5, and 8 the result will be 3 to start with
    5 appended and 8 appended appearing as "3, 5, 8" in the text box.

    There are various reasons I'm doing this and one is because I'm using
    an existing script and trying to create new fields for entry and
    retreival would be convoluted. This might actually be a reasonable
    workaround. Thanks so much for your help...
    Marc, Feb 3, 2005
    #1
    1. Advertising

  2. On Wed, 02 Feb 2005 21:44:00 -0500, Marc wrote:

    > I want to have one varchar or text field hold the value of several
    > checkbox items as one string. For example, let's say I have 10 movies
    > and want to list them in a string for the person to state their top 3.
    > So if they check boxes 3, 5, and 8 the result will be 3 to start with
    > 5 appended and 8 appended appearing as "3, 5, 8" in the text box.



    Rename text boxes like so:

    <input type="checkbox" name="movies[]" value="1">movie1

    etc...

    USe the PHP join() function liek so:

    $string = join("," $movies);

    Voila!

    --
    Jeffrey Silverman

    ** Drop "PANTS" to reply by email
    Jeffrey Silverman, Feb 3, 2005
    #2
    1. Advertising

  3. Marc

    Marc Guest

    On Wed, 02 Feb 2005 22:36:10 -0500, Jeffrey Silverman
    <> wrote:

    >On Wed, 02 Feb 2005 21:44:00 -0500, Marc wrote:
    >
    >> I want to have one varchar or text field hold the value of several
    >> checkbox items as one string. For example, let's say I have 10 movies
    >> and want to list them in a string for the person to state their top 3.
    >> So if they check boxes 3, 5, and 8 the result will be 3 to start with
    >> 5 appended and 8 appended appearing as "3, 5, 8" in the text box.

    >
    >
    >Rename text boxes like so:
    >
    ><input type="checkbox" name="movies[]" value="1">movie1
    >
    >etc...
    >
    >USe the PHP join() function liek so:
    >
    >$string = join("," $movies);
    >
    >Voila!


    Thanks so much. It was a beast figuring out where to put it.
    Evidently, I think you have a typo in the syntax which should be

    $string = join(",", $movies);

    Which has the extra comma as join(1,2) passes two variables. :)
    Worked great....
    Marc, Feb 3, 2005
    #3
  4. Marc

    JDS Guest

    JDS, Feb 3, 2005
    #4
  5. Marc

    Toby Inkster Guest

    Marc wrote:

    > I want to have one varchar or text field hold the value of several
    > checkbox items as one string.


    This is a bad idea and will cause you problems further down the line.
    Google for "first normal form" and why it's a bad idea to violate it.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Feb 3, 2005
    #5
  6. Marc

    Marc Guest

    On Thu, 03 Feb 2005 19:28:02 +0000, Toby Inkster
    <> wrote:

    >Marc wrote:
    >
    >> I want to have one varchar or text field hold the value of several
    >> checkbox items as one string.

    >
    >This is a bad idea and will cause you problems further down the line.
    >Google for "first normal form" and why it's a bad idea to violate it.


    The idea has been working great but for the entries in several fields
    I'm getting an error

    "Duplicate entry '5' for key 1"

    on several variations. Thanks for the info and I will check although
    I'm not sure what this would have to do with normalizing a relational
    dabase (I think that's what it means, first, second, third normal
    forms...)
    Marc, Feb 4, 2005
    #6
  7. Marc

    JDS Guest

    JDS, Feb 4, 2005
    #7
    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. macyp
    Replies:
    2
    Views:
    8,373
    MWells
    Jan 26, 2005
  2. Patrick Olurotimi Ige

    How to pass CheckBox Values(1/0 ) to another page?

    Patrick Olurotimi Ige, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,006
    Patrick Olurotimi Ige
    Jun 12, 2005
  3. samir dsf
    Replies:
    1
    Views:
    2,016
    Patrick.O.Ige
    Nov 10, 2005
  4. cwwilly
    Replies:
    1
    Views:
    459
    Christophe Vanfleteren
    Apr 19, 2004
  5. cwwilly
    Replies:
    4
    Views:
    138
    Vincent van Beveren
    Apr 21, 2004
Loading...

Share This Page