473,440 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,440 software developers and data experts.

Checkbox validation issue

Hi,

In my form, I have a checkbox that must be checked in order to process
the form. By default, I want it to be checked when the page first
appears. I can do that easily enough by hardcoding the "checked"
property.

My problem occurs when I try to validate it.

If the visitor unchecks the checkbox, the form cannot be processed,
and I must allow the user to correct the problem (along with any other
fields that were not filled out correctly).

I want to use CSS to change the labels of any missing or bad fields to
red. That part seems to be coded correctly (see below).

<tr>
<td colspan="2" class="<? echo (!isset($checkTelephone_err) ?
'form-labels-error ' : 'form-labels'); ?>"><input
name="checkTelephone" type="checkbox" value="OK2Call"> Yes, I
authorize you to contact me via telephone.</td>
</tr>

The part that I'm not sure about is how to default the checkbox to
checked when the form first appears, and yet allow for
unchecking/checking after the form is submitted a first time.

Sorry. I know the explanation is a bit vague. I'm having trouble
elaborating well. If you have any tips or suggestions, please let me
know.

- Eric
Jul 17 '05 #1
2 8419
Eric Linders wrote:
<snip>
The part that I'm not sure about is how to default the checkbox to
checked when the form first appears, and yet allow for
unchecking/checking after the form is submitted a first time.


Try:

<?php
if (empty($_POST) || (isset($_POST['checkTelephone'] &&
$_POST['checkTelephone'] == "OK2Call")
echo ' checked="checked"';
?>

When the form is first accessed, $_POST will be empty, and of course if
$_POST is not empty and the value of checkTelephone is set, the box should
still be checked...

// Ian Fette
// Proponent comp.lang.php
Jul 17 '05 #2
This doesn't sound like a php issue, unless you are sending the form
to a php script then want to output the results back to the browser
with the differnt colors.

two ways,

1: server side, php
post the form to your script, validate it, if fails send it back to
user, with new color

2: client side, javascript
define two styles
..normal {font-color:#000000; ,bla, bla,}
..bad {font-color:#FF0000; ,bla, bla,}
with an onSubmit() do your validation then asign new style
document.formname.inputboxname.class = "bad";


Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Earl Teigrob | last post by:
I wanted my "Terms and Conditions" Checkbox control to participate in my ASP.NET validation just like all the the other controls on the page. After some time of searching the web for an example of...
2
by: Asha | last post by:
greetings i want to use the required field validator control to validate a checkbox. here is the code implemented. <asp:RequiredFieldValidator ID="rfv" ControlToValidate="chkDistiAudit"...
5
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.......
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
5
by: nescio | last post by:
hello, i am making a form using php/html/javascript a part of the form is (email address) comming from a database. the amount of addresses is always different. every address has a checkbox....
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
7
by: karen987 | last post by:
The code below is for a checkbox, in a form on an asp page. I want to make it mandatory for the user to click it. The other validation statements work fine, this one causes a problem though. The...
0
by: Ned Balzer | last post by:
I posted this this morning but it never went through, so I am trying again -- apologies for the duplication if so. I need to validate several checkboxes on an asp.net 2.0 page. I don't need to...
1
by: sureshl | last post by:
Error in client side validation object expected error in this line,--> OnClientClick="return validation1(<%=maxnumber %>); Syntax error : in this line :for(i=0;i<maxno;i++) i want to validate...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.