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.
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
|
|
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
|
|
This week users
