Hello all,
Is there any method other than running a for loop to check if a value exists in select box using js???? Im looking for something like document.getElementById('selbox').valueExists('myval');
Hello all,
Is there any method other than running a for loop to check if a value exists in select box using js???? Im looking for something like document.getElementById('selbox').valueExists('myval');
you can do it with jquery
Use the Attribute Equals Selector
see in
in javascript you can run like
for (var i=0; i<document.getElementById('mySelect').options.length; i++)
{
if (document.getElementById('mySelect').options[i].text == seachtext)
{
alert('found');
break;
}
}
You can't extend the methods the select
-element has. So there will not be a solution without an extra function to check for the existence of a value in a select
.
A "solution" without a loop could be the following...
function SelectHasValue(select, value) {
obj = document.getElementById(select);
if (obj !== null) {
return (obj.innerHTML.indexOf('value="' + value + '"') > -1);
} else {
return false;
}
}