RE: [PHP] Checkbox related...

2003-02-16 Thread Ernest E Vogelsinger
At 20:34 16.02.2003, Dhaval Desai said:
[snip]
>How do we do it using the first option i.e javascript to count how many 
>boxes are checked...could you give some example...
[snip] 

Warning - untested:


function validateChecks()
{
aboxes = Array('box1','box2','box3','box4','box5');
hF = document.forms['myform'];
if (hF) {
for (i = 0, count=0; i < aboxes.length; i++) {
   hBox = hF.elements[aboxes[i]];
   if (hBox.checked) {
   ++count;
   if (count >= 2)
   return true;
   }
}
}
return false;
}















I believe you get the idea...


-- 
   >O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Checkbox related...

2003-02-16 Thread Dhaval Desai
How do we do it using the first option i.e javascript to count how many 
boxes are checked...could you give some example...

Thanx

-Dhaval






From: "David McInnis" <[EMAIL PROTECTED]>
To: "'Dhaval Desai'" <[EMAIL PROTECTED]>
Subject: RE: [PHP] Checkbox related...
Date: Sun, 16 Feb 2003 10:59:17 -0800

You can use javascript to count the number of items checked or you can
check the size of your array once the form has been submitted to the
server.

David

-Original Message-
From: Dhaval Desai [mailto:[EMAIL PROTECTED]]
Sent: Sunday, February 16, 2003 10:58 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Checkbox related...

Hi everybody,

I have a form with 5 checkboxes. I want to make sure that a user checks
atleast 2 boxes before he can proceed. How can that be made possible.

Thank you

-Dhaval





_
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



_
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Checkbox related...

2003-02-16 Thread Ernest E Vogelsinger
At 19:57 16.02.2003, Dhaval Desai said:
[snip]
>I have a form with 5 checkboxes. I want to make sure that a user checks 
>atleast 2 boxes before he can proceed. How can that be made possible.
[snip] 

You have 2 options:

1) Client-side JavaScript: in the forms OnSubmit handler, loop your
checkboxes and make sure at least 2 are checked. If the precondition is not
met, return false from the onSubmit handler.

2) Server-Side via PHP: make an array of all available checkboxes, and walk
this array to see if you have at least 2 of these checkboxes set in your
$_REQUEST array. If the precondition is not met, retransmit the original
form without proceeding.

I'd prefer a combination of both - the JS method saves the user an
unnecessary form transmission, speeding up his entry. The server-side
script method makes sure there's no malicious user trying to trick the
system *g*


-- 
   >O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php