Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

  View Other C# .NET Posts   Ask New Question  Ask New Question With Power Editor

checkbox calculation with php
Theunis Lombard posted at Saturday, November 07, 2009 12:25 PM

I'm rather new to php and i am stuck.
i want to have a single checkbox be calculated with php, which i partially get done, but when the checkbox is not selected, php does not recognize the cb1 index with $_POST["cb1"]. When the checkbox is selected, no errors are given.
Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0
Re:
web mavin provided a rated reply to Theunis Lombard on Saturday, November 07, 2009 10:40 PM

Well I think thats a correct behavior..when your checkbox is checked it'd surely work fine. When checked, the variable name will contain the value of the checkbox. Look at the somewhat simimlar samples at the below links:-

http://www.globalissa.com/articles/articleCheckbox.php

http://www.smartwebby.com/PHP/Phptips2.asp

Reply    Reply Using Power Editor
  Rank Winnings Points
November 8 $22.00 56
October 7 $38.00 131

You need to prefix your check condition with the ISSET function too.
[)ia6l0 iii provided a rated reply to Theunis Lombard on Sunday, November 08, 2009 1:26 PM

If your check box markup looks like:
<input type="checkbox" name="myCheckBox" value="Yes" />

The check box "mycheckbox" would have a value in the post array only if the checkbox is checked. Otherwise the value would be nothing.  so ensure that you check if the value is set and to checked. You can do it like:

<?php
if(isset($_POST['myCheckBox']) && $_POST['myCheckBox'] == 'Yes') 
{
   echo "checked.";
}
else
{
   echo "not checked";
}
?>
Reply    Reply Using Power Editor
  Rank Winnings Points
November 1 $217.00 560
October 1 $226.00 771