473,320 Members | 1,957 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,320 software developers and data experts.

Validation of Checkbox and Dropdownlist

I am trying to use the following script to see determine whether a
dropdownlist has a value in it or to see whether a checkbox has been checked.
I don't want the user to be able to do both. In other words I don't want a
user to check a checkbox and choose an item from a drop-down list box. I
want them to do one action or the other.
Here is my script to try and do this but im not sure if my logic is correct
as I get an error no matter what I do. Can someone please help me.

<script language=javascript>
function ValidateDropDownOrCheckBox(sender, args)
{
if ( document.WebForm2.DropDownList1.value ||&&
document.WebForm2.CheckBox1.checked )
{
args.IsValid = true;
return;
}
else
args.IsValid = false;
}
</script>

This is how I refer to this script
<asp:CustomValidator id="cvRepApp" runat="server" Font-Size="Medium"
ErrorMessage="Must enter either or"
ClientValidationFunction="ValidateDropDownOrCheckB ox">*</asp:CustomValidator>

Thanks for any help anyone can give me
Nov 22 '05 #1
2 2644
You'll want to replace your ValidateDropDownOrCheckBox() function with
something like the following:

var ddl = document.WebForm2.DropDownList1;
var cb = document.WebForm2.CheckBox1;
args.IsValid = ((ddl.selectedIndex>0 && !cb.checked) ||
(ddl.selectedIndex==0 && cb.checked));

The first line sets the variable "ddl" to your drop-down-list.
The second line sets the variable "cb" to your checkbox.
The third line sets args.IsValid to true when (1) the ddl has an item
selected and the checkbox is not checked, or (2) the ddl has the 0th item
selected and the checkbox checked.

Hope that helps.

--
Jason Whitted
Nov 22 '05 #2
this worked great however I need to also add something in so as checkbox2 is
incorporated. Its ok for checkbox1 &2 to be ticked as long as Dropdownlist
box is not filled in and its ok for checkbox2 to be ticked providing
dropdownlist box is not filled again. Can you help me re-write the code to
include this please.

"JWhitted" wrote:
You'll want to replace your ValidateDropDownOrCheckBox() function with
something like the following:

var ddl = document.WebForm2.DropDownList1;
var cb = document.WebForm2.CheckBox1;
args.IsValid = ((ddl.selectedIndex>0 && !cb.checked) ||
(ddl.selectedIndex==0 && cb.checked));

The first line sets the variable "ddl" to your drop-down-list.
The second line sets the variable "cb" to your checkbox.
The third line sets args.IsValid to true when (1) the ddl has an item
selected and the checkbox is not checked, or (2) the ddl has the 0th item
selected and the checkbox checked.

Hope that helps.

--
Jason Whitted

Nov 22 '05 #3

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

Similar topics

0
by: Stephen | last post by:
Could someone please help me with some validation. I have to write code which checks to see whether a dropdown list is populated with a value or a checkbox is checked. I want the code to run on the...
1
by: Stephen | last post by:
I am trying to use the following script to see determine whether a dropdownlist has a value in it or to see whether a checkbox has been checked. I don't want the user to be able to do both. In...
0
by: Stephen | last post by:
I have some code which I call from a custom validator however I seem to have got the logic wrong and im having trouble figuring out how to write my code to get things to work the way I require....
7
by: Stephen | last post by:
I have some code which I call from a custom validator however I seem to have got the logic wrong and im having trouble figuring out how to write my code to get things to work the way I require....
0
by: Krish | last post by:
Hello Gurus, Pl. help. I need to validate a control in datagrid based on check box selection. Basically in a datagrid i have checkbox and textbox control for edititemtemplate. If checkbox is...
1
by: Buddy Ackerman | last post by:
I don't know what the problem is. I have a form with several controls that need to be validated, I put a validation group in every form control, every validatoino control, the submit button and...
0
by: Nathan Sokalski | last post by:
I have written a Validator (a class that inherits from the BaseValidator class), and it includes client-side validation functions. The validator is a conditional validator that only validates if a...
1
by: raam | last post by:
Hi, I have ajax tab container with 6 tabs in it. I need to validate each tab contents separately and the validtaion summary must be separate for each tab. i cannot do that only one summary is...
5
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 ...
1
by: janetb | last post by:
I have a gridview with an update capabilities - a textbox column (roomName), a dropdownlist(orgID), a dropdownlist(roomTypeID),a checkbox column (dialOut), a checkbox column (dialIn). When I try to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.