Re: Dynamically check radio buttons
| From: | Shew | Date: | Thu, 01 Aug 2002 15:19:09 +0000 |
| Subject: | Re: Dynamically check radio buttons | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110681@lists.php.net to get a copy of this message | ||
OK, changed the subject to what I think it should be about.
Anybody?
"Shew" <babydragon4@excite.com> wrote in message
news:20020731141657.80369.qmail@pb1.pair.com...
> Hi - I'm a TOTAL php NEWBIE - my 1st bit of code!!!.
>
> Basically the input form page has 17 sets of radio buttons, each
> representing one game with 2 options - team 1 and team 2. What I want to
do
> is a better way of checking each radio button value instead of using an if
> statement for each. This code doesn't really work - it finds that vars
> ALWAYS exist.
>
> IE:
>
> <INPUT NAME=Game1 VALUE=1>Chicago
> <INPUT NAME=Game1 VALUE=2>whatever
>
> <INPUT NAME=Game2 VALUE=3>Minny
> <INPUT NAME=Game2 VALUE=1>Nobody
>
> Code above is processed by the following code:
>
> for ($GameIdx = 1; $GameIdx <= 17; $GameIdx++) {
> /* instead "hardcoding each radio button name - just do it
programmatically
> by concatenating / creating the name */
> $frmGame = "Game" + $GameIdx;
> if ($frmGame) {
> /* U want to check if the length is 5 or 6 bytes because it could be
> "game1" or "game14" */
> $Length = strlen($frmGame);
> if ($Length == 5) {
> $GetNumber = 1;
> }
> else {
> $GetNumber = 2;
> }
>
> $GameID = intval(substr($frmGame, $Length - $GetNumber, $GetNumber));
> print "Game ---> $GameIdx - $frmGame - $GetNumber - $GameID <BR>";
> if ($GameID == $GameIdx) {
> print "Yeah Match - $GameID = $GameIdx <BR>";
> /* OK, here is where U want to do the actual insert */
> }
> } /* $frmGame endif */
> }
>
> ?>
>
>
> Thanks
>
>
>