You are here: Re: - setting checkboxes « HTML « IT news, forums, messages
Re: - setting checkboxes

Posted by Sonnich on 08/07/06 19:38

Jonathan N. Little wrote:
> Sonnich wrote:
>
> [You are improperly snipping who wrote what quote which can get quite
> confusing, try to keep or replace quoted author notices which I have
> restored to show you....]
>
>
> >> Sonnich wrote:
> >>>
> >>> I found that it should work here too:
> >>>
> >>> if( !(isset($_POST[$part1[$i]]) && ($_POST[$part1[$i]] ==
> >>> "")) )
> >>> echo " checked";
> >>> else
> >>> echo "";
> >>>
> >>> Idea: checkbox is default checked, but only if set and set to nothing
> >>> it is not set.
> >>> Boolean algebra. Only if set, and set to nothing, then it is not set.
> >>>
> >>> But by some reason it does not work. I have done this a 147533 times,
> >>> and here it does not work. Why?
> >>>
>
> > Jonathan wrote:
> >>
> >> I think a misplaced closing parentheses:
> >>
> >
> > You were right. This is what I have now:
> >
> > if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] ==
> > "") )
> > echo " checked";
> > else
> > echo "";
> >
> > but is still does not work. It sets them first time as it should, but
> > after that it inverts the selection.
> > I dont get it.
> >
> > Any ideas anyone?
> >
>
> Not enough info to determine, need URL and your source code. What you
> you me by 'sets them'? Sets what? And 'after the first time'? Are your
> reposting to the same script?

Yes, I am reposting to the same script. An example:


<html>
<form method=post name='myform' action='sjjtest.php'><!-- same file -->
<table>
<?
$part1[]="a";
$part1[]="b";
$part1[]="c";
for($i=0; $i<count($part1); $i++)
{
echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
value=\"true\"";
if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
echo " checked";
echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
.."</td></tr>";
}
?>
<tr><td><input class="box" name="apply_selection" type="submit" value="
Apply selection "></td></tr>
</table>
</form>
</html>

Try it and you will see

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация