Ik heb een script gevonden wat ik graag wil gebruiken alleen geeft hij een fout:
options.text is leeg of geen object. Nu doet het script voor de rest wat ik zoek maar
ik heb echter niet zoveel verstand van javascript. Is er iemand die mij kan helpen, wat zou ik moeten veranderen?
Hieronder het betreffende script:
<HTML>
<SCRIPT>
<!--
function combotext_onkeydown(e,oText,oSelect){
keyCode = e.keyCode;
if (keyCode == 40 || keyCode == 38) {
oSelect.style.display = 'block';
oSelect.focus();
comboselect_onchange(oSelect, oText);
}
else if (keyCode == 13) {
e.cancelBubble = true;
if (e.returnValue) e.returnValue = false;
if (e.stopPropagation) e.stopPropagation();
comboselect_onchange(oSelect, oText);
oSelect.style.display='none';
oText.focus();
return false;
}
else if(keyCode == 9) return true;
else { //alert(keyCode);
oSelect.style.display = 'block';
var c = String.fromCharCode(keyCode);
c = c.toUpperCase();
toFind = oText.value.toUpperCase() + c;
for (i=0; i < oSelect.options.length; i++){
nextOptionText = oSelect.options.text.toUpperCase();
if(toFind == nextOptionText){
oSelect.selectedIndex = i;
break;
}
if(i < oSelect.options.length-1){
lookAheadOptionText = oSelect.options[i+1].text.toUpperCase() ;
if( (toFind > nextOptionText) && (toFind < lookAheadOptionText) ){
oSelect.selectedIndex = i+1;
break;
}
}
else {
if(toFind > nextOptionText) {
oSelect.selectedIndex = oSelect.options.length-1; // stick it at the end
break;
}
}
}
}
}
function comboselect_onchange(oSelect,oText) {
if(oSelect.selectedIndex != -1)
oText.value = oSelect.options[oSelect.selectedIndex].text;
}
function comboselect_onkeyup(keyCode,oSelect,oText){
if (keyCode == 13) {
comboselect_onchange(oSelect, oText);
oSelect.style.display='none';
oText.focus();
}
}
// -->
</SCRIPT>
<body onclick="document.getElementById('selectInput').style.display='none'">
<FORM name=form1>
<DIV STYLE="position:relative">
<INPUT TYPE="text" NAME=textInput SIZE=18 AUTOCOMPLETE="OFF" ONKEYDOWN="combotext_onkeydown(event, this, this.form.selectInput)">
<SELECT NAME=selectInput SIZE=8 STYLE="display:none; position:absolute; top:20px; left:0px" ONBLUR="this.style.display='none'" ONCHANGE="comboselect_onchange(this, this.form.textInput)" ONKEYUP="comboselect_onkeyup(event.keyCode, this, this.form.textInput)">
<OPTION VALUE="Kansas City">Kansas City</OPTION>
<OPTION VALUE="Overland Park">Overland Park</OPTION>
<OPTION VALUE="St. Louis">St. Louis</OPTION>
</SELECT>
<DIV>
</FORM>
</BODY>
</html>
options.text is leeg of geen object. Nu doet het script voor de rest wat ik zoek maar
ik heb echter niet zoveel verstand van javascript. Is er iemand die mij kan helpen, wat zou ik moeten veranderen?
Hieronder het betreffende script:
<HTML>
<SCRIPT>
<!--
function combotext_onkeydown(e,oText,oSelect){
keyCode = e.keyCode;
if (keyCode == 40 || keyCode == 38) {
oSelect.style.display = 'block';
oSelect.focus();
comboselect_onchange(oSelect, oText);
}
else if (keyCode == 13) {
e.cancelBubble = true;
if (e.returnValue) e.returnValue = false;
if (e.stopPropagation) e.stopPropagation();
comboselect_onchange(oSelect, oText);
oSelect.style.display='none';
oText.focus();
return false;
}
else if(keyCode == 9) return true;
else { //alert(keyCode);
oSelect.style.display = 'block';
var c = String.fromCharCode(keyCode);
c = c.toUpperCase();
toFind = oText.value.toUpperCase() + c;
for (i=0; i < oSelect.options.length; i++){
nextOptionText = oSelect.options.text.toUpperCase();
if(toFind == nextOptionText){
oSelect.selectedIndex = i;
break;
}
if(i < oSelect.options.length-1){
lookAheadOptionText = oSelect.options[i+1].text.toUpperCase() ;
if( (toFind > nextOptionText) && (toFind < lookAheadOptionText) ){
oSelect.selectedIndex = i+1;
break;
}
}
else {
if(toFind > nextOptionText) {
oSelect.selectedIndex = oSelect.options.length-1; // stick it at the end
break;
}
}
}
}
}
function comboselect_onchange(oSelect,oText) {
if(oSelect.selectedIndex != -1)
oText.value = oSelect.options[oSelect.selectedIndex].text;
}
function comboselect_onkeyup(keyCode,oSelect,oText){
if (keyCode == 13) {
comboselect_onchange(oSelect, oText);
oSelect.style.display='none';
oText.focus();
}
}
// -->
</SCRIPT>
<body onclick="document.getElementById('selectInput').style.display='none'">
<FORM name=form1>
<DIV STYLE="position:relative">
<INPUT TYPE="text" NAME=textInput SIZE=18 AUTOCOMPLETE="OFF" ONKEYDOWN="combotext_onkeydown(event, this, this.form.selectInput)">
<SELECT NAME=selectInput SIZE=8 STYLE="display:none; position:absolute; top:20px; left:0px" ONBLUR="this.style.display='none'" ONCHANGE="comboselect_onchange(this, this.form.textInput)" ONKEYUP="comboselect_onkeyup(event.keyCode, this, this.form.textInput)">
<OPTION VALUE="Kansas City">Kansas City</OPTION>
<OPTION VALUE="Overland Park">Overland Park</OPTION>
<OPTION VALUE="St. Louis">St. Louis</OPTION>
</SELECT>
<DIV>
</FORM>
</BODY>
</html>