troubleshooting Question

Validate a field, based on a user dropdown selection

Avatar of bootneck2222
bootneck2222 asked on
4 Comments1 Solution272 ViewsLast Modified:

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;


Any help would be greatly appreciated.
chaitu chaitu

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros