Click here to Skip to main content
16,009,598 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends , i have requirement on one dropdownlist values is minimum experience 1 to 20 and second dropdownlist is maximum experience 1 to 25. how to validates the two dropdownlist values using jquery. if i select the second drowdownlist values less the first dropdownlist values i want get the validition using jquery. as well as if we select the second dropdownlist is not empty and first dropdownlist is empty then getting the validation message and other validations also working on that dropdownlists.
Posted
Comments
So, what have you tried? Where is the problem?

1 solution

Lets say you have two dropdown lists:
HTML
<select id="ddlMinExp">
  <option value="0">Select Minimum Exp</option>
  <option value="1">1</option>
          ......
          .......
  <option value="20">20</option>
</select>

And,
HTML
<select id="ddlMaxExp">
  <option value="0">Select Maximum Exp</option>
  <option value="1">1</option>
          ......
          .......
  <option value="25">25</option>
</select>


Then you can check the values through jQuery as -

JavaScript
$(function(){
    $('#ddlMaxExp').change(function(){
       var selectedMaxValue = Number($(this).val());
       var selectedMinValue = Number($('#ddlMinExp').val());
        
       if( selectedMaxValue > 0  && selectedMinValue > selectedMaxValue) {
           alert('Minimum experience cannot be less than maximum experience');
           $(this).find('option:first').attr('selected', 'selected'); //reset the second dropdown list
       }
       else if( selectedMaxValue > 0 && selectedMinValue === 0) {
           alert('Please select minimum experience first');
           $(this).find('option:first').attr('selected', 'selected'); //reset the second dropdown list
       }       
       
    });
});


JSFiddle : http://jsfiddle.net/c3UV3/[^]

Hope this helps
Thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900