hi all,
can someone, please tell me how to validate the following checkboxes?
<divid="cbService"style="display: inline;">
<inputid="CheckBox2"runat="server"type=CheckBoxValue="Email"/>Email<inputid="CheckBox3"runat="server"type=CheckBoxValue="Mainframe"/>Mainframe
<inputid="CheckBox6"runat="server"type=CheckBoxValue="JDL"/>JDL<br/>
<inputid="CheckBox7"runat="server"type=CheckBoxValue="Tiburon"/>Tiburon<inputid="CheckBox8"runat="server"type=CheckBoxValue="iasWorld"/>iasWorld
</div>
Thanks in advance
You have to use a "CustomValidator" and create a javascript function:
function ValidateCheckboxes(src, args)
{
if(!document.getElementById("<%=CheckBox2.ClientID %>").checked && !document.getElementById("<%=CheckBox3.ClientID%>").checked ...)
args.IsValid = false;
}
else
{
args.IsValide = true;
}
Thanks for your prompt response.
Just so I understand clearly, I have got to do this for chebobox2 through checkbox8?
Can someone, anyone, please help?
This javascript code is giving me error:
<scriptLanguage="JavaScript"Type="text/javascript">function ValidateCheckboxes(src, args)
{
if(!document.getElementById("<%=CheckBox1.ClientID %>").checked
&& !document.getElementById("<%=CheckBox2.ClientID%>").checked&& !document.getElementById("<%=CheckBox3.ClientID %>").checked
&& !document.getElementById("<%=CheckBox4.ClientID %>").checked&& !document.getElementById("<%=CheckBox5.ClientID %>").checked
&& !document.getElementById("<%=CheckBox6.ClientID %>").checked&& !document.getElementById("<%=CheckBox7.ClientID %>").checked
&& !document.getElementById("<%=CheckBox8.ClientID %>").checked&& !document.getElementById("<%=CheckBox9.ClientID %>").checked
&& !document.getElementById("<%=CheckBox10.ClientID %>").checked&& !document.getElementById("<%=CheckBox11.ClientID %>").checked&& !document.getElementById("<%=CheckBox12.ClientID %>").checked)
args.IsValid =false;}
else
{
args.IsValide =true;}
</script>
The error is on the ELSE line.
It says, "}" expected.
However, when I add the "}", the validation seems to work but other controls disappear. What could I be doing wrong?
Thanks much
Try to put this javascript function at the end of your page. If it doesn't work, please put some of the aspx code (especially the controls that are disappearing in order to check it.
you have no opening bracket after the if brackets...
should look like this:
<scriptLanguage="JavaScript"Type="text/javascript">function ValidateCheckboxes(src, args)
{
if(!document.getElementById("<%=CheckBox1.ClientID %>").checked
&& !document.getElementById("<%=CheckBox2.ClientID%>").checked&& !document.getElementById("<%=CheckBox3.ClientID %>").checked
&& !document.getElementById("<%=CheckBox4.ClientID %>").checked&& !document.getElementById("<%=CheckBox5.ClientID %>").checked
&& !document.getElementById("<%=CheckBox6.ClientID %>").checked&& !document.getElementById("<%=CheckBox7.ClientID %>").checked
&& !document.getElementById("<%=CheckBox8.ClientID %>").checked&& !document.getElementById("<%=CheckBox9.ClientID %>").checked
&& !document.getElementById("<%=CheckBox10.ClientID %>").checked&& !document.getElementById("<%=CheckBox11.ClientID %>").checked&& !document.getElementById("<%=CheckBox12.ClientID %>").checked)
{
args.IsValid =false;}
else
{
args.IsValide =true;}
Oops!! Sorry
, LD50 is correct.
If you're using FireFox I highly suggest adding on FireBug. It is an excellent Javascript debugger.
Hi simflex,
I think you also select my comment (the one that I provided the code of the validation function) as an answer since this was the answer, eventhough it was missing a "}".
Thanks in advance.
No comments:
Post a Comment