Find a Beatle
by js_test
HTML
<input id="FindBeatle" type="text" />
<select id="Beatles">
<option>John</option>
<option>Paul</option>
<option>George</option>
<option>Ringo</option>
</select>
<input type="button" id="submit" value="submit" />
JavaScript
var SelectBeatle = function(){
var sel = document.getElementById('Beatles'),
val = document.getElementById('FindBeatle').value,
len = sel.options.length;
for(var i = 0; i < len; i++) {
if(sel.options[i].innerHTML !== val) continue;
sel.selectedIndex = i;
return;
}
alert(val + " is Missing!");
};
var btn = document.getElementById('submit'),
fnc = function(event){
SelectBeatle();
};
btn.addEventListener('click', fnc);