1

Using this example from Validation Plug-in's 'required (dependency-expression)' explanation:

$("#myform").validate({
  rules: {
    details: {
      required: "#other:checked"
    }
  }, debug:true
});
$("#other").click(function() {
    $("#details").valid();
});

I'm trying to make the text input required if radio button #guide is selected in example below:

<input type="radio" id="outfitter" name="memtype" value="Outfitter" />Outfitter $125
<input type="radio" id="guide" name="memtype" value="Guide" />Guide $75
<input type="text" id="sponout" name="sponout" size="75" />

I just don't know where to place

 $("#other").click(function() {
    $("#details").valid();
 });

within rules validation coding.

0

1 Answer 1

2

Here's one way you could do this:

$("#myform").validate({
    rules: {
        sponout: {
            required: "#guide:checked"
        }
    }
});

$("input[name='memtype']").change(function () {
    $("#myform").valid();
});

Example: http://jsfiddle.net/kqczf/1/

Sign up to request clarification or add additional context in comments.

2 Comments

OK, gotcha. I'll give 'er a whirl. Thanx, particularly for the fiddle example.
Dropped final '.change function' code section and worked fine. Realized I could simply add required:"condition terms" as you pointed out, Andrew.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.