Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

custom validator

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
I'm trying to validate a form I have to make sure that at least one of the form elements is filled in. I am already using compare validators on a couple, so i decided to try the custom validator, even though it seems meant for only one control.

I created a dummy textbox to test this, here is the aspx code for it:
Code:
<asp:TextBox id=&quot;txtValidate&quot; runat=&quot;server&quot;></asp:TextBox>
<br />
<asp:CustomValidator id=&quot;CustomValidator1&quot; runat=&quot;server&quot; ControlToValidate=&quot;txtValidate&quot; ErrorMessage=&quot;You must fill in at least one field.&quot; Display=&quot;dynamic&quot; OnClientValidate=&quot;verifyForm&quot;></asp:CustomValidator>

and here is the JS function, since i'm using OnClientValidate:
Code:
<script language=&quot;javascript&quot;>
    function verifyForm( oSrc, txtValue )
    {
    alert(&quot;test&quot;);
        var found = 0;
        for (var x = 0; x < document.Form1.length; x++) {
            if (!(document.Form1.elements[x].value==&quot;&quot;)) {
                found = 1;
            }
        }
        
        if (found == 0)
        {
            return false;
        } 
        else
        {
            return true;
        }
    }
</script>

its doesn't even enter the function, just submits the form... anyone have any ideas?

Thanks.
 
no one has ever needed to do something like this huh?
 
Not I
This is really just a shot in the dark but try adding () to the end of your function call.

asp:CustomValidator id=&quot;CustomValidator1&quot; runat=&quot;server&quot; ControlToValidate=&quot;txtValidate&quot; ErrorMessage=&quot;You must fill in at least one field.&quot; Display=&quot;dynamic&quot; OnClientValidate=&quot;verifyForm()&quot;></asp:CustomValidator>

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top