Hov der mangler jquery script i toppen
Se mit eksempel nedenfor her. Det er testet. Kopiere og sæt ind. og prøv så filtrer combobox med fx. "jyl"
<script src="
https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><div style="width: 100%; float: left;">
<div style="float: left;">
<input style="width: 400px; height: 30px; font-size: 16px;" id="search_inputNy" onkeyup="SplitOrdNy();" value="" placeholder="Filtrer nedenfor. (Max 5 ord)">
</div>
<input id="TextNy1" type="hidden" name="TextNy1" value="" />
<input id="TextNy2" type="hidden" name="TextNy1" value="" />
<input id="TextNy3" type="hidden" name="TextNy1" value="" />
<input id="TextNy4" type="hidden" name="TextNy1" value="" />
<input id="TextNy5" type="hidden" name="TextNy1" value="" />
</div>
<div style="width: 100%; float: left;">
<select id="SelectCombobox" name="SelectCombobox">
<option value=""></option>
<option value="Odense - Fyn">Odense - Fyn</option>
<option value="Bogense - Fyn">Bogense - Fyn</option>
<option value="Esbjerg - Jylland">Esbjerg - Jylland</option>
<option value="Århus - Jylland">Århus - Jylland</option>
<option value="København - Sjælland">København - Sjælland</option>
<option value="Roskilde - Sjælland">Roskilde - Sjælland</option>
</select>
<script type="text/javascript">
function SplitOrdNy(){
var search_input = document.getElementById("search_inputNy").value;
words = search_input.split(' ');
var Text1 = document.getElementById("TextNy1");
var Text2 = document.getElementById("TextNy2");
var Text3 = document.getElementById("TextNy3");
var Text4 = document.getElementById("TextNy4");
var Text5 = document.getElementById("TextNy5");
if(words[0] != ""){ Text1.value = words[0]; }else{ Text1.value = ""; }
if(words[0] != ""){ Text2.value = words[1]; }else{ Text2.value = ""; }
if(words[0] != ""){ Text3.value = words[2]; }else{ Text3.value = ""; }
if(words[0] != ""){ Text4.value = words[3]; }else{ Text4.value = ""; }
if(words[0] != ""){ Text5.value = words[4]; }else{ Text5.value = ""; }
}
$(document).ready(function () {
//copy options
var options = $('#SelectCombobox option').clone();
//react on keyup in textbox
$('#search_inputNy').keyup(function () {
$('#SelectCombobox').empty();
var val = $('#TextNy1').val().toLowerCase();
var val2 = $('#TextNy2').val().toLowerCase();
var val3 = $('#TextNy3').val().toLowerCase();
var val4 = $('#TextNy4').val().toLowerCase();
var val5 = $('#TextNy5').val().toLowerCase();
//take only the options containing your filter text or all if empty
options.filter(function (idx, el) {
if(val5 != "undefined"){
return val === '' || (
$(el).text().toLowerCase().indexOf(val) >= 0 &&
$(el).text().toLowerCase().indexOf(val2) >= 0 &&
$(el).text().toLowerCase().indexOf(val3) >= 0 &&
$(el).text().toLowerCase().indexOf(val4) >= 0 &&
$(el).text().toLowerCase().indexOf(val5) >= 0);
}else if(val4 != "undefined"){
return val === '' || (
$(el).text().toLowerCase().indexOf(val) >= 0 &&
$(el).text().toLowerCase().indexOf(val2) >= 0 &&
$(el).text().toLowerCase().indexOf(val3) >= 0 &&
$(el).text().toLowerCase().indexOf(val4) >= 0);
}else if(val3 != "undefined"){
return val === '' || (
$(el).text().toLowerCase().indexOf(val) >= 0 &&
$(el).text().toLowerCase().indexOf(val2) >= 0 &&
$(el).text().toLowerCase().indexOf(val3) >= 0);
}else if(val2 != "undefined"){
return val === '' || (
$(el).text().toLowerCase().indexOf(val) >= 0 &&
$(el).text().toLowerCase().indexOf(val2) >= 0);
}else{
return val === '' || (
$(el).text().toLowerCase().indexOf(val) >= 0);
}
}).appendTo('#SelectCombobox');//add it to list
});
});
</script>
</div>