G
Guest
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. Below is the script I currently use
and what it does along with what I would like it to do. Can someone please
help me work how I can fix this.
<script>
function ValidateDropDownOrCheckBox(sender, args)
{
if ( document.forms[0].DropDownList1.value ||
( document.forms[0].CheckBox2.checked &&
document.forms[0].CheckBox1.checked )
)
{
args.IsValid = true;
return;
}
args.IsValid = false;
}
</script>
<asp:CustomValidator id="cvRepApp" runat="server" Font-Size="Medium"
ErrorMessage="Must enter either or"
ClientValidationFunction="ValidateDropDownOrCheckBox">*</asp:CustomValidator>
MY PROBLEMS WITH THIS CODE ARE: -
At present the page is redirected if both checkboxes are checked and
something is selected in the dropdown list. This needs to show an error
Also the page shows an error if ONLY one checkbox is checked AND nothing is
selected in the dropdown list. I want this sequence to be allowed.
It also allows the page to redirect if one checkbox is checked and something
is selected in the dropdown list. This need to show an error.
I NEED MY LOGIC TO WORK LIKE SO: -
If I tick one of the checkboxes (and nothing is selected in the
dropdownlist) I want the arg to be TRUE (in other words allow page event to
run)
If I tick both of the checkboxes (and nothing is selected in the
dropdownlist) I want the arg to be TRUE (in other words allow page event to
run)
If neither checkbox is checked but something is selected in the dropdownlist
then I want the arg to be TRUE (in other words allow page event to run)
If niether checkbox is checked and nothing is selected in the dropdownlist
then i want the arg to be FALSE (in other words SHOW ERROR MESSAGE)
got the logic wrong and im having trouble figuring out how to write my code
to get things to work the way I require. Below is the script I currently use
and what it does along with what I would like it to do. Can someone please
help me work how I can fix this.
<script>
function ValidateDropDownOrCheckBox(sender, args)
{
if ( document.forms[0].DropDownList1.value ||
( document.forms[0].CheckBox2.checked &&
document.forms[0].CheckBox1.checked )
)
{
args.IsValid = true;
return;
}
args.IsValid = false;
}
</script>
<asp:CustomValidator id="cvRepApp" runat="server" Font-Size="Medium"
ErrorMessage="Must enter either or"
ClientValidationFunction="ValidateDropDownOrCheckBox">*</asp:CustomValidator>
MY PROBLEMS WITH THIS CODE ARE: -
At present the page is redirected if both checkboxes are checked and
something is selected in the dropdown list. This needs to show an error
Also the page shows an error if ONLY one checkbox is checked AND nothing is
selected in the dropdown list. I want this sequence to be allowed.
It also allows the page to redirect if one checkbox is checked and something
is selected in the dropdown list. This need to show an error.
I NEED MY LOGIC TO WORK LIKE SO: -
If I tick one of the checkboxes (and nothing is selected in the
dropdownlist) I want the arg to be TRUE (in other words allow page event to
run)
If I tick both of the checkboxes (and nothing is selected in the
dropdownlist) I want the arg to be TRUE (in other words allow page event to
run)
If neither checkbox is checked but something is selected in the dropdownlist
then I want the arg to be TRUE (in other words allow page event to run)
If niether checkbox is checked and nothing is selected in the dropdownlist
then i want the arg to be FALSE (in other words SHOW ERROR MESSAGE)