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 6131533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:59:12+00:00 2026-05-23T16:59:12+00:00

using jquery I want to make a selection from a select box required (ie

  • 0

using jquery I want to make a selection from a select box required (ie it can’t be left as the blank default) if a particular checkbox is ticked. My code:

$(document).ready(function(){
  $("#myForm").validate({
    rules: {
      myDropDown: {
        required: {       
          depends: function(element) {
            return $("#myCheckbox:checked")
          }
        }
      }
    }
  })
})

The html:

<input type="checkbox" name="myCheckbox" id="myCheckbox" value="1">
<select name="myDropDown" id="myDropDown">
  <option value="" selected></option>
  <option value="1">Choice 1</option>
  <option value="2">Choice 2</option>
  <option value="3">Choice 3</option>
</select>

Not only is the code not working it’s throwing out the jquery tabs that I have as the next section of javascript.

Any advice appreciated.

Edit: Now that I’ve sorted out all my brackets the behaviour now is that it’s making the select box a required field whether or not the checkbox is checked – ie the depends part is not working. Other javascript on the page is now working ok.

  • 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-23T16:59:12+00:00Added an answer on May 23, 2026 at 4:59 pm

    Please try like this

    $(document).ready(function(){
      $("#myForm").validate({
        rules: {
           myDropDown:{
              required: function (element) {
                 if($("#myCheckbox").is(':checked')){
                     var e = document.getElementById("myDropDown");
                     return e.options[e.selectedIndex].value=="" ;                            
                 }
                 else
                 {
                     return false;
                 }  
              }  
           }
        }
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a text box allow only letters (a-z) using jQuery. Any
I want to make an auto complete system using Jquery from the yahoo pipes
I create select element dynamically using jquery, and I want to make action when
I want to make a page so I can select filters in a jquery
I want to make a check box checked automatically (using jquery) when a user
I want make datetimepicker in my project. Using jquery how it is possible? I
I have a set of divs that I want to make collapsible/expandable using jQuery's
I am using jQuery to make a website, and I want to be able
I have a standard select box which I'm populating using jquery by appending options,
I'm using jQuery UI accordion() . I have 4 tabs. I want to make

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.