SELECT и кирилица

3 отговора 188 прегледа
#1

SELECT и кирилица

Здравейте - имам форма със селект със държавите в света.

Проблема е че акоса написани на латиница и натисна саответен клавиш от клавиатурата веднага отивам на първата страна със съответната буква, но ако страните са изписани на кирилица това не работи.

Има ли някакъв варянт да работи и на кирилица.

Например
<select...>
<option value="1"> Албания
<option value="2"> Дания
<option value="3"> Норвегия
<option value="4"> Япония
</select>

Ако натисна "Н" от клавиатурата да отида директно на Норвегия

Предварително ви благодаря

Отговор
в отговор на fan #2

Не работи...

в ИЕ... Нищо, някой ден ще го оправят.

There are three determined states the cat could be in: Alive, Dead, and Bloody Furious.
Отговор
в отговор на Koтapakът нa Шpьoдинrep #3

Re: Не работи...

Нима? В моя това си работи като слънце и с кирилица, и с латиница:


var typeAheadInfo = {last:0,
accumString:"",
delay:200,
timeout:null,
reset:function() {this.last=0; this.accumString=""; this.ala=-1;},
ala:-1
};

function typeAhead(sIndex) {
if(typeAheadInfo.ala == -1)
typeAheadInfo.ala = sIndex;
if (window.event && !window.event.ctrlKey) {
var now = new Date();
if (typeAheadInfo.accumString == "" || now - typeAheadInfo.last < typeAheadInfo.delay) {
var evt = window.event;
var selectElem = evt.srcElement;
var charCode = evt.keyCode;
var newChar = String.fromCharCode(charCode).toUpperCase();
typeAheadInfo.accumString += newChar;
var selectOptions = selectElem.options;
var txt, nearest;
var to = selectOptions.length;
var from = (typeAheadInfo.ala+1 == to) ? 0 :
typeAheadInfo.ala+1;
for (var i = from; i < to; i++) {
txt = selectOptions.text.toUpperCase();
nearest = (typeAheadInfo.accumString >
txt.substr(0, typeAheadInfo.accumString.length))
? i : nearest;
if (txt.indexOf(typeAheadInfo.accumString) == 0) {
clearTimeout(typeAheadInfo.timeout);
typeAheadInfo.last = now;
typeAheadInfo.timeout = setTimeout("typeAheadInfo.reset()", typeAheadInfo.delay);
selectElem.selectedIndex = i;
evt.cancelBubble = true;
evt.returnValue = false;
return false;
}
if (i+1 == selectOptions.length) {
i = -1;
to = typeAheadInfo.ala;
}
}
if (nearest != null) {
selectElem.selectedIndex = nearest;
}
} else {
clearTimeout(typeAheadInfo.timeout);
}
typeAheadInfo.reset();
}
return true;
}



<select onkeypress="typeAhead(this.selectedIndex)"...>

Успех.

Има три вида хора. Част от проблема, част от решението и част от пейзажа.
Отговор
в отговор на mr.vain #4

Така...

може и да работи... То сичко работи в IE ако им оправиш бъговете... За справка:

[линк]

There are three determined states the cat could be in: Alive, Dead, and Bloody Furious.
Отговор