We help IT Professionals succeed at work.
Get Started

Validate a field, based on a user dropdown selection

bootneck2222 asked
Last Modified: 2013-12-05

I would like the form below to validate the colour2 field, if the colour field is set to other. At present its not working. The contents of the validate2.js script is also below:



<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/validate2.js"></script>
<title>Registration Form</title>

<style type="text/css">
		display: block;
		color: #FF0000;
		font-style: bold;

<form method="POST" id="registerForm" action="next_stage.php">

<select size="1" name="colour">
						<option selected value="">Select....</option>
						<option value="blue">Blue</option>
						<option value="red">Red</option>
						<option value="other">Other</option>
					<input type="text" name="colour2" id="colour2"/>

<input type="submit" value="Submit" name="B1">



        rules: {
               colour: "required",
               colour2: {
	               required: function(element) {
	              var flag = false;
	                    flag = true;
	                  return flag;


Open in new window

Any help would be greatly appreciated.
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE