We help IT Professionals succeed at work.
Get Started

Jquery validation and backround-color for select.valid

Panos
Panos asked
on
760 Views
Last Modified: 2012-05-09
Hello experts.
I using jquery.validate plugin and i want to style the selects that are required false.I want to get green backround to show that the element is OK.
This is working for other inputs but not for the selects.
Below is my code
<style type="text/css" media="screen" >
select {background-color:#FFC; width:200px}
select.valid {background-color: #9F3; width:200px}
select.error {background-color: #F03; width:200px}
input {background-color:#FFC; width:200px}
input.valid {background-color: #9F3; width:200px}
input.error {background-color: #F03; width:200px}
label.error {
	display:block;
	font-size:.8em;
	font-weight:normal;
	font-style:italic;
	color:red;
	margin-left:.5em;
	background-color: transparent;
}
label.error:hover { background:transparent}
label.valid {
	display: block;
	width: 16px;
	height: 16px;
	}

</style>
<FORM NAME="forgotpw" id="forgotpw" METHOD="POST" ACTION="#CGI.SCRIPT_NAME#">
<table align="center"  cellspacing="0" cellpadding="0">
<tr>
  <td width="20%" rowspan="4" align="center"></td>
  <td width="40%">Choose your secret question (required):</td>
  <td width="40%">
<select name="clue1"  id="clue1">
       <option value="">Select</option>
       <option value="1">What is your favorite color?</OPTION>
       <option value="2">What is the name of your favorite pet?</OPTION>
       <option value="3">What are the last five digits of your Social Security Number?</OPTION>
  </select>
</td>
</tr>
<tr>
<td>Your stored answer is (required):</td>
<td><input type="text" name="clue2" maxlength="50"  value="" ></td>
</tr>
<tr>
<td>Your stored answer is (required):</td>
<td><input type="text" name="clue3" maxlength="50"  value="" class="TfR" ></td>
</tr>

<tr>
  <td>&nbsp;</td>
  <td colspan="2" style="padding-bottom:20px">
<Button type="submit"  name="Register" value="" />Send</button></td>
 </tr>
</table>
</FORM>

<script language="javascript" type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.validate.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
   $("#forgotpw", $(this)).validate({
     rules: {
       clue1: {required: false},
	   clue2: {required: false},
       clue3: {required: true}
      
      
     },
     messages: {
      clue3: "Name is required"
     }
    })
 });
</script>

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
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