Search:
Welcome Guest | Register | Login
logo

How to check a value exists or not in a dropdown by using jquery/javascript

I want to check a value exists in my ddlCity dropdown or not by using either jQuery ro JavaScript.

  • C#
  • jQuery
  • JavaScript
2
 
Asked: 26 Feb 2013
Reputation: 114
Alysa Kosteski
2 Answers

Check this:

var IsExists = false;
$('#ddlCity option').each(function(){
    if (this.value == 'valuetocheck') 
        IsExists = true;
    return IsExists;        
});
3
 
Answered: 26 Feb 2013
Reputation: 1,074
Myghty

By using pure JavaScript:

var IsExists = false;
var ddloption =  document.getElementById('select-box').options;
for(var i = 0; i < ddloption.length; i++)
{    if( ddloption[i].value === 'valuetocheck' )
    {   
        IsExists = true; 
        break;        
    }    
}    
return IsExists;
1
 
Answered: 26 Feb 2013
Reputation: 1,418
Alicia Gonzalez
Login to post your answer