-1

I'm using Jquery Validate plugin and i have two fields like these :

<input id="nbextr" name="nbextr" class="form-control" type="text" title="Ex: 3" 
value="" tabindex="3"  />
<input id="nbextr2" name="nbextr2" class="form-control" type="text" title="Ex: 3" value="" tabindex="4"  />

I need that only one of these two fields is not empty.

And i don't find a basic solution.

Portekoi
  • 1,087
  • 2
  • 22
  • 44
  • 1
    possible duplicate of [jQuery Validation - Two fields, only required to fill in one](http://stackoverflow.com/questions/8137844/jquery-validation-two-fields-only-required-to-fill-in-one) - you cannot have looked very hard – mplungjan Sep 25 '13 at 12:57
  • possible duplicate of [jQuery Validate: Validate that one field, or both fields of a pair are required](http://stackoverflow.com/questions/18993067/jquery-validate-validate-that-one-field-or-both-fields-of-a-pair-are-required) – Sparky Sep 25 '13 at 14:48
  • You would use the `require_from_group` method included in [the `additional-methods.js` file](http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js). See [this link for usage](http://stackoverflow.com/questions/18993067/jquery-validate-validate-that-one-field-or-both-fields-of-a-pair-are-required). – Sparky Sep 25 '13 at 14:49

1 Answers1

-1

I don't know how to do it with validate but i did the trick like this :

$("#nbextr").blur(function() {
    if($("#nbextr").val().length > 0){
    $("#nbextr2").val("");
    }
});

And the same for the other field.

Portekoi
  • 1,087
  • 2
  • 22
  • 44
  • 1
    You asked for a jQuery Validate solution and your answer has nothing to do with that. See: http://stackoverflow.com/questions/18993067/jquery-validate-validate-that-one-field-or-both-fields-of-a-pair-are-required – Sparky Sep 25 '13 at 14:52
  • I know, thanks. but i was need a solution so i do that for waiting. Your link is for validate at least one field. So only nbextr or nbextr2. Like a Radio button. – Portekoi Sep 25 '13 at 18:17