Jump to content


Photo

limiting the number of checkboxes checked


  • Please log in to reply
6 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 13 September 2006 - 01:12 AM

hey guys,

I'm trying to limit the number of checkboxes a user can check. Need the limit to be dynamic but for testing purposes I'm trying to do it with a fixed number.

the checkboxes look like this

<input type="checkbox" name="winner[]" value="'.$row['username'].'">

is there any way of doing that if the name of the checkbox is an array? It really needs to be like that.

#2 degsy

degsy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 18 September 2006 - 02:59 PM

http://degs.co.uk/te...check_limit.htm
http://degs.co.uk/te...t_php_array.php
http://degs.co.uk/te..._limit_to_1.htm

#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 18 September 2006 - 05:27 PM

thanks! but can you please tell me what's the php for though?

#4 degsy

degsy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 19 September 2006 - 01:30 PM

Link 2 does. Maybe you should look at it  ::)

#5 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 19 September 2006 - 06:11 PM

lol what I meant was, what does the php do in all of this, why does it check a db?

#6 degsy

degsy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 20 September 2006 - 10:23 AM

It's a generic example. You take that part you need and work with it.

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 September 2006 - 12:48 PM

The pseudo-code for the function should look like the following:

-iterate through all form elements
-check each element for trailing "[]"
-iterate though the elements .length
-count the times .checked is true
-validate against "allowed" number
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users