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($checkT elephone_err) ?
'form-labels-error ' : 'form-labels'); ?>"><input
name="checkTele phone" 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 2 8427
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="checke d"';
?>
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
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.formna me.inputboxname .class = "bad";
Mike Bradley http://gzen.myhq.info -- free online php tools This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 how to do this, I created
the script to do it and thought I would share it. Its a littel messy but
does the job. If anyone has a better solution, please let me know.
//Client Site Event Handler to put in Page_Load event...
|
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"
ErrorMessage="error" runat="server" />
<asp:checkbox id="chkDistiAudit" runat="server" CssClass="objControl_left"
Width="100px" Text="Disti Audit" Checked="True"></asp:checkbox>
|
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....
2. after population there should be validation in checkboxlist.....
that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on the form.......
these 2 steps should be...
|
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 function needs to run and
validate all the checkboxes on my form and make sure none of them are
unchecked. I suck at Javascript and my problem is 2fold. I have the
following code that constructs the checkbox
response.write "<input type=checkbox...
|
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.
people have the check at least one checkbox.
i have made a form check to see of at least one checkbox is selected.
this workts fine.
| |
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. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named 'CheckAllRows' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the...
|
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 browser returns a debug error, i don't get the validation javascript alert below, instead the browser says:
error: document.frm.opt15. is null or not an object
and invites me to debug.
when i debug it points to the below code, i wonder what...
|
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 validate that they are checked; instead, I am trying to
prevent potential SQL or code injection via checkbox controls. These
checkboxes are inside a formview.
I found examples (e.g at http://msdn2.microsoft.com/en-us/library/aa479013.aspx)
of...
|
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 atleast a single checkbox to be selected ...
also i dont know how to do server side side validation for this generated checkboxes ....and then need to display the selected checkbox after validation.....??
<head>
<script language="javascript">
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |