Hey guys,
In a form of 3 checkboxes, at least one of them has to be checked. How would
I go about making sure at least one is checked before the form is submitted?
If it's not checked, an alert pops up saying at least one has to be checked.
Thanks in advance! 8 1878
John wrote on 30 sep 2005 in comp.lang.javas cript: In a form of 3 checkboxes, at least one of them has to be checked. How would I go about making sure at least one is checked before the form is submitted? If it's not checked, an alert pops up saying at least one has to be checked.
<form onsubmit='retur n checkForIt()' ...
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
"Evertjan." wrote John wrote on 30 sep 2005 in comp.lang.javas cript:
In a form of 3 checkboxes, at least one of them has to be checked. How would I go about making sure at least one is checked before the form is submitted? If it's not checked, an alert pops up saying at least one has to be checked.
<form onsubmit='retur n checkForIt()' ...
-- Evertjan. The Netherlands. (Replace all crosses with dots in my emailaddress)
if it helps, checkForIt() would look something like
------------------------
function checkForIt(){
fr1 = document.forms["form1"];
if(!fr1.ch1.che cked && !fr1.ch2.checke d && !fr1.ch3.checke d){
alert("at least one needs to be checked");
}
}
------------------------
given a form named 'form1' and checkboxes named 'ch1' etc.
-alu
alu wrote on 01 okt 2005 in comp.lang.javas cript: "Evertjan." wrote John wrote on 30 sep 2005 in comp.lang.javas cript:
> In a form of 3 checkboxes, at least one of them has to be checked. > How would I go about making sure at least one is checked before the > form is submitted? If it's not checked, an alert pops up saying at > least one has to be checked. >
<form onsubmit='retur n checkForIt()' ...
if it helps, checkForIt() would look something like ------------------------ function checkForIt(){ fr1 = document.forms["form1"]; if(!fr1.ch1.che cked && !fr1.ch2.checke d && !fr1.ch3.checke d){ alert("at least one needs to be checked"); } }
The function needs to return true/false:
<form onsubmit='retur n checkForIt()' ...
....
function checkForIt(){
fr1 = document.forms["form1"];
if (fr1.ch1.checke d || fr1.ch2.checked || fr1.ch3.checked )
return true;
alert("At least one checkbox needs to be checked");
return false;
}
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
"John" <gt*****@mail.g atech.edu> wrote in message
news:dh******** **@news-int2.gatech.edu ... Hey guys,
In a form of 3 checkboxes, at least one of them has to be checked. How would I go about making sure at least one is checked before the form is submitted? If it's not checked, an alert pops up saying at least one has to be checked.
dont use a check box use a radio group....
"Zoe Brown" <zo***********@ N-O-S-P-A-A-Mtesco.net> wrote in message
news:iR******** ********@newsfe 5-gui.ntli.net... "John" <gt*****@mail.g atech.edu> wrote in message news:dh******** **@news-int2.gatech.edu ... Hey guys,
In a form of 3 checkboxes, at least one of them has to be checked. How would I go about making sure at least one is checked before the form is submitted? If it's not checked, an alert pops up saying at least one has to be checked.
dont use a check box use a radio group....
radio group for ONLY one checked
check boxes for AT LEAST one checked, which is the requirement.
-alu
On 30/09/2005 23:00, alu wrote:
[snip] function checkForIt(){ fr1 = document.forms["form1"]; if(!fr1.ch1.che cked && !fr1.ch2.checke d && !fr1.ch3.checke d){ alert("at least one needs to be checked"); } } ------------------------ given a form named 'form1'
It would be better, in my opinion, to pass a reference to the form when
calling the function (making a form name/id redundant).
and checkboxes named 'ch1' etc.
If the checkboxes are related, they should have the same name attribute
value.
function isChecked(group ) {
for(var i = 0, n = group.length; i < n; ++i) {
if(group[i].checked) {return true;}
}
return false;
}
function validate(form) {
var elements = form.elements;
if(!isChecked(e lements['cbox-name'])) {
alert('At least one checkbox should be selected.');
return false;
}
return true;
}
<form action="..." onsubmit="retur n validate(this); ">
Or some variation, thereof.
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ***********@194 .109.133.242... function checkForIt(){ fr1 = document.forms["form1"]; if (fr1.ch1.checke d || fr1.ch2.checked || fr1.ch3.checked ) return true; alert("At least one checkbox needs to be checked"); return false; }
Thanks! How would I go about adding syntax to make it check for another
function to be true before it returns true as a whole?
For instance:
if (fr1.ch1.checke d || fr1.ch2.checked || fr1.ch3.checked ) && (function
blabla return true)
return true;
Thanks in advance!
John wrote on 03 okt 2005 in comp.lang.javas cript: "Evertjan." <ex************ **@interxnl.net > wrote in message function checkForIt(){ fr1 = document.forms["form1"]; if (fr1.ch1.checke d || fr1.ch2.checked || fr1.ch3.checked ) return true; alert("At least one checkbox needs to be checked"); return false; }
Thanks! How would I go about adding syntax to make it check for another function to be true before it returns true as a whole?
For instance:
if (fr1.ch1.checke d || fr1.ch2.checked || fr1.ch3.checked ) && (function blabla return true) return true;
Try it out for yourself. The above won't work, John.
Letting others do all the work is not the way of this NG.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fred |
last post by:
Hi,
I defined a form consisting of checkboxes like:
<form>
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
.....
<input type="checkbox" name=ck id=ck onclick="check(this.form)"
</form>
|
by: Jack |
last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that
builds the sql string.
In the front end asp page, the checkbox code is written as follows:
<i><input type="checkbox" name="chk_Complete" value="<%Response.Write
l_IsChecked%>"<%if cbool(l_IsChecked) then Response.Write " checked"%>>
The code to captures the checkbox value in the asp page that builds the sql
string is follows
|
by: Piotr |
last post by:
how can I read (in alert for example) array index number of checked
checkbox?
I have:
<input type="checkbox" id="id_number" name="check" value="1"
onclick="show()"/>
<input type="checkbox" id="id_number" name="check" value="2"
onclick="show()"/>
<input type="checkbox" id="id_number" name="check" value="3"
|
by: feanor |
last post by:
I need to select children checkboxes when selecting the parent one.
This is my function:
function SelectChildrens(checkbox_name){
form = document.forms;
Sname = checkbox_name.split("-");
for (i=0;i<form.elements.length;i++){
THATname = form.elements.name.split("-");
if (Sname.length==1){
if (THATname==Sname){
|
by: iforsyth |
last post by:
Have a paging datagrid with a checkbox control in column(0).
ViewState is enabled.
I check the checkbox in first row of the grid on a page and then
the program hits this event:
Private Sub dgRegGrid_PageIndexChanged(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
dgRegGrid.PageIndexChanged
I then do a loop to check the checkbox state.
| |
by: mahsa |
last post by:
my problem dosent solve yet I want to have
claa void in onclick of my check bov if I us
function setProps ( )
msg.innerText = "llll";
in <datalist>
<ItemTemplate><input type="checkbox" id="cbItem" runat="server" onclick="test()
value='<%#DataBinder.Eval(Container.DataItem, "PartNo")%>' NAME="cbItem"><%#DataBinder.Eval(Container.DataItem, "PartNo")%><td class='item_content' width='83'><input value=4 maxLength='4' size='4'...
|
by: Dexter |
last post by:
Hello all,
I have a datagrid with a template column with checkbox, and at this template
column,
at header section, i have a checkbox with autopostback property as true,
and when i check this checkbox i need to check all others.
But i don't can to use the ItemDataBoundEvent, because this event, is called
once only.
I need to check all checkbox of column when the user to check this checkbox
of header section.
|
by: Daz |
last post by:
Hi everyone.
Firstly, I apologise if this i not what you would call a PHP problem. I
get quite confused as to what lives in which realm, so if this
shouldn't be posted here, please suggest where I should post it.
I have created a form, which consists of a list of items, each with a
checkbox. When a checkbox is checked or unchecked, the page should be
refreshed. During the refresh, the data is validated and the MySQL
database is...
|
by: Amer Neely |
last post by:
I've got a dynamically built form with checkboxes for each element ( a
list of file names in a directory). I need to grab only those checkboxes
that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group
them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear
with me, things are a little different in that country.
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |