Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:51:23+00:00 2026-05-29T09:51:23+00:00

I want a field to become required only when a specific option is selected

  • 0

I want a field to become required only when a specific option is selected or a specific radio button is selected or when a specific string is entered in a text input field (All of the required( dependency-expression ) examples I can find assume that the dependency is whether an input is checked / unchecked or filled/unfilled in the case of text fields)

Here is an example of what I need, based on a radio section:

Marital Status (the required field):

<input name="status" id='status'type="radio" value="couple" checked="checked" />
<input name="status" id='status'type="radio" value="single male"  />
<input name="status" id='status'type="radio" value="single female" />

Partners Name (the dependent field – required only when ‘Couple’ is selected from above)

<input name="partner" type="text"  id="partner">

Example 2: Required field = Venue

<select name="venue" id="venue">
<option value="">Please select venue</option>
<option>London EC1</option>
<option>London E9</option>
<option>Birmingham</option>

etc.
Dependent field = user (only required for one of the above selections, say ‘Birmingham’)

<input name="user" type="text" id="user">

How do I adapt the example shown athttp://docs.jquery.com/Plugins/Validation/Methods/required#dependency-expression for the above situations?

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

I have tried:

user: {
      required: "#venue:('birmingham')"
    }

and

partner: {
      required: "#status:('couple')"
    }

but these have the effect of making user and partner required regardless of results in venue and status

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:51:23+00:00Added an answer on May 29, 2026 at 9:51 am

    For the first one, your radio inputs should have different id’s:

    <input name="status" id='statusCouple' type="radio" value="couple" checked="checked" />
    <input name="status" id='statusSingleMale' type="radio" value="single male"  />
    <input name="status" id='statusSignleFemale' type="radio" value="single female" /> 
    

    Then your rule can look like this:

    partner: {
      required: "#statusCouple:checked"
    }
    

    For the second one, just make your rule like this:

    user: {
      required: function(element) { return $("#venue").val() == 'Birmingham'; }
    }       
    

    Should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the required field validator to become only visible whenever there is an
I want to make a field required only if another field is answered in
I have a disabled text field that I want to become enabled when I
I want to reset a file upload field when the user selects another option.
I want to replace the 'client' field text box in fogbugz when you edit
I want to align a Custom Button Field (the Star on the Screenshot) to
I want to make an input field that has a min-width of 25px and
Say, i have a text field with some text in it, and i want
When a user selects a file, I want another file field to appear. It
I want to add same field to multiple tables. Can I do this with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.