Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Pass Multiple Checkbox Values

Reply
Thread Tools

Pass Multiple Checkbox Values

 
 
Marc
Guest
Posts: n/a
 
      02-03-2005
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...


 
Reply With Quote
 
 
 
 
Jeffrey Silverman
Guest
Posts: n/a
 
      02-03-2005
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


 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      02-03-2005
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....
 
Reply With Quote
 
JDS
Guest
Posts: n/a
 
      02-03-2005
On Thu, 03 Feb 2005 00:47:01 -0500, Marc wrote:

> 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);


Yes, I did have a typo.

--
JDS |
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      02-03-2005
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

 
Reply With Quote
 
Marc
Guest
Posts: n/a
 
      02-04-2005
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...)


 
Reply With Quote
 
JDS
Guest
Posts: n/a
 
      02-04-2005
On Thu, 03 Feb 2005 23:57:07 -0500, Marc wrote:

> "Duplicate entry '5' for key 1"


This error means exactly what it says.

--
JDS |
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
urg-how to pass multiple values and receive them. samir dsf ASP .Net 1 11-10-2005 08:33 AM
How to pass CheckBox Values(1/0 ) to another page? Patrick Olurotimi Ige ASP .Net 0 06-12-2005 05:37 AM
pass multiple values from one aspx page to another macyp ASP .Net 2 01-26-2005 05:25 PM
Pop-Up Pass Multiple Dynamic Values Between Forms cwwilly Javascript 4 04-21-2004 07:17 AM
Pop-Up Pass Multiple Dynamic Values Between Forms cwwilly Java 1 04-19-2004 05:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57