jQuery form sumbission if at least one dropdown is selected

Hi Experts,
The code below makes all 4 dropdown menus required. My goal is to make it possible to submit the form, if at least one dropdown is selected. It doesn't matter which one, but at least one must be selected. How can the code be modified in order to achieve this goal? Or could you help me please with any other solution, jQuery or Javascript?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/screen.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<script>
	$().ready(function() {
	
		$("#mydropdowns").validate({
		  messages: {
			Affiliation: {
			  required: "Please select an affiliation.",
			},
			DeviceName: {
			  required: "Please select a device."
			},
			AliasName: {
				required: "Please select an alias."
			},
			DeviceAccountID: {
				required: "Please select an Account ID"
			}
		  }
		});

	});
	</script>

</head>
<body>

<form id="mydropdowns" method="POST" action="../Search/SearchResults.asp">
  <select name="Affiliation" id="Affiliation" required>
  <option value=""></option>
  <option value="VER">VER</option>
  <option value="TIR">TIR</option>
  <option value="SAV">SAV</option>
  <option value="ASE">ASE</option>
</select>
  <select name="DeviceName" id="DeviceName" required>
  <option value=""></option>
  <option value="100968_FILE1">100968_FILE1</option>
  <option value="101324_FILE1">101324_FILE1</option>
  <option value="101325_FILE1">101325_FILE1</option>
  <option value="101333_FILE1">101333_FILE1</option>
</select>
<select name="AliasName" id="AliasName" required>
  <option value=""></option>
  <option value="021850">021850</option>
  <option value="024803">024803</option>
  <option value="026294">026294</option>
  <option value="050403">050403</option>
</select>
<select name="DeviceAccountID" id="DeviceAccountID" required>
  <option value=""></option>
  <option value="100968">100968</option>
  <option value="101324">101324</option>
  <option value="101333">101333</option>
  <option value="101335">101335</option>
</select>
  <br/><br/>
  <input type="submit" value="submit" />
</form>
</div>
</body>
</html>

Open in new window


I would really appreciate your help.
romsomIT DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Firstly you have made all of your select's required using the required attribute - that is going to force a selection on each one so remove that attribute

Then you will need to use the require_from_group rule which requires the additional-methods.min.js library

This means moving your messages into the messages property. Putting it all together you get this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/screen.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.16.0/jquery.validate.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.16.0/additional-methods.min.js"></script>

<script>
  $().ready(function() {
  
    $("#mydropdowns").validate({
      rules: {
      Affiliation: {
        require_from_group: [1, ".select-group"]
      },
      DeviceName: {
        require_from_group: [1, ".select-group"]
      },
      AliasName: {
        require_from_group: [1, ".select-group"]
      },
      DeviceAccountID: {
        require_from_group: [1, ".select-group"]
      }
      },
       messages: {
      Affiliation: {
        require_from_group: "Please select an affiliation."
      },
      DeviceName: {
        require_from_group: "Please select a device."
      },
      AliasName: {
        require_from_group: "Please select an alias."
      },
      DeviceAccountID: {
        require_from_group: "Please select an Account ID"
      }
      }
    });

  });
  </script>

</head>
<body>

<form id="mydropdowns" method="POST" action="../Search/SearchResults.asp">
  <select name="Affiliation" id="Affiliation" class="select-group">
  <option value=""></option>
  <option value="VER">VER</option>
  <option value="TIR">TIR</option>
  <option value="SAV">SAV</option>
  <option value="ASE">ASE</option>
</select>
  <select name="DeviceName" id="DeviceName" class="select-group">
  <option value=""></option>
  <option value="100968_FILE1">100968_FILE1</option>
  <option value="101324_FILE1">101324_FILE1</option>
  <option value="101325_FILE1">101325_FILE1</option>
  <option value="101333_FILE1">101333_FILE1</option>
</select>
<select name="AliasName" id="AliasName" class="select-group">
  <option value=""></option>
  <option value="021850">021850</option>
  <option value="024803">024803</option>
  <option value="026294">026294</option>
  <option value="050403">050403</option>
</select>
<select name="DeviceAccountID" id="DeviceAccountID" class="select-group">
  <option value=""></option>
  <option value="100968">100968</option>
  <option value="101324">101324</option>
  <option value="101333">101333</option>
  <option value="101335">101335</option>
</select>
  <br/><br/>
  <input type="submit" value="submit" />
</form>
</div>
</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
romsomIT DeveloperAuthor Commented:
Thank you very much for the solution and also for the link you provided. It will also help me with other projects.
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.