<script type="text/javascript" src="http://code.jquery.com/jquery-
latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/
plugins/validate/jquery.validate.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function() {
      $("#form1").validate({
        rules: {
           title: {
                required: true,
                 minlength:40
        } ,
        content: {
                required: true,
                 minlength:100,
                 maxlength:600
        },
         evaluation: {
                required: true,
                 minlength:50,
                 maxlength:300
        },
        price: {
                required: true,
                digits:true

        },
        multi:{
                required:true
        }
             },
        messages: {

        }
              });
            });

-->
</script>

As you can see from the code above, "title", "content", "evaluation",
"prices" and "multi" are required. All of them are required. But there
are additional two fields, which are "participations" and "days". Only
one of them is required. Either "participations" or "days" is
required. How to write this code?

On Oct 12, 10:17 am, Phper <hi.steven...@gmail.com> wrote:
> A good clue. But I still don't know where to write the "if" statement.
> It would be good if you can give me an example.
>
> On Oct 11, 10:57 pm, Don Dunbar <salemd1s...@gmail.com> wrote:
>
> > Hi, if you are using the validation plugin, I believe it has a function
> > "addMethod" that allows you to write your own method for the validation. It
> > requires a name (javascript identifier), a method to check input against (
> > in your case A and B would be checked for completion) and a message to
> > display when there is an error (i.e. neither A nor B is filled out, or both
> > are). You can get the details for using the "addMethod" function at the
> > jQuery Docs page.http://docs.jquery.com/Plugins/Validation
> > The page lists demos and the function you need is toward the bottom of the
> > page.
>
> > The logic is fairly straight forward :  when the form is being filled out
> > listen for when A and B have focus, remember if either is checked or ignored
> > and check to make sure both are not simultaneously filled out. Check this on
> > submit as well.
>
> > Good luck,
> > DED
>
> > On Sun, Oct 11, 2009 at 7:42 AM, Phper <hi.steven...@gmail.com> wrote:
>
> > > How can I write the code in the context of Jquery validate function?
>
> > > On Oct 11, 12:43 pm, Don Dunbar <salemd1s...@gmail.com> wrote:
> > > > Hi, javascript has an 'xor' operator. It works just like 'or' in an 'if'
> > > > statement except in 'xor' only one side can be true. In a normal 'or'
> > > > statement either side can be true or both can. So you probably want to 
> > > > do
> > > > something like: if ( A XOR B) { } .  Then only one can be true to
> > > continue
> > > > if both are true the statement returns 'false'.Hope this helps.
> > > > DED
>
> > > > On Sat, Oct 10, 2009 at 10:37 PM, Phper <hi.steven...@gmail.com> wrote:
>
> > > > > There are two input fields in a form, but only one of them is
> > > > > required, they are not required at the same time. Either A or B is
> > > > > required. ( A is required  OR B is required). In other words, a user
> > > > > can input data to field A, or he can input data to filed B, but he can
> > > > > not input data to Both A and B at the same time.
>
> > > > > How to implement this constraint in Jquery form validation?

Reply via email to