1

http://blog.rebeccamurphey.com/2009/04/15/jquery-validation-indicate-that-at-least-one-element-in-a-group-is-required/

jQuery Validate - require at least one field in a group to be filled

I tried above both solution for my jquery validation..every thing working fine but its very slow..some times IE throwing error like "some scripts are running slow and it may effect your system performance or something like that"..

I know what is causing this issue...i do have 20 fields on my page..and each field is calling that method more than once and its like 20 times 2 or more than that...its my guess..i am not pretty is that the cause for my problem..is any using that solution..is any one have this issue..or am I missing something..

I tried to post a question in the stackoverflow link..but i am not supposed to that..thats why i am creating this question...please anyone have some idea about it.. please help me... thanks a lot..

Community
  • 1
  • 1
Sunny43
  • 129
  • 1
  • 4
  • 15

1 Answers1

0

You could use a simple jQuery script like the following to do the validation.

This will basically loop through all the input text fields within your form, check if any have a value and then submit if one or more are filled in, if not it will display an error message to the screen and prevent the form from being submitted.

<script type="text/javascript">
    $(function() {
        $('form').submit(function() {
            var isValid = false;
            $(this).find('input:text').each(function() {
                if ($(this).val().length > 0)
                    isValid = true;
            });

            if (!isValid) 
                $('#ErrorMsg').text('Please fill in one of the fields!');

            return isValid;
        }); 
    });
</script>

This may improve your performance issues as it only preforms the validation when submitting the form.

Hope this helps!

BRIXER
  • 1
  • thanks...i saw this solution previously.. this works fine..but i am getting performance issue if i am trying use the above mentioned solutions..your solution will display a global error but i am trying to highlight all inputs if noting is filled and removes the error highlighting once we got focus on any one of the fields..anyway thanks for your solution... – Sunny43 May 27 '11 at 15:30