Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Vagabondis

Busca Dinâmica em um ComboBox!

Recommended Posts

Galera,(Y)Digamos que eu tenho um ComboBox na minha página com vários itens. Gostaria de fazer com que quando a pessoa apertar uma letra o cursor vá para o primeiro registro daquela letra!Alguém sabe onde tem isso para eu pegar? <_< Alguém sabe fazer ou já tem pronto? <_<

Compartilhar este post


Link para o post
Compartilhar em outros sites

<HTML><HEAD>

<BODY onload=java script:setUp()>

<script>

<!--

function SelObj(formname,selname,textname,str) {

this.formname = formname;

this.selname = selname;

this.textname = textname;

this.select_str = str || '';

this.selectArr = new Array();

this.initialize = initialize;

this.bldInitial = bldInitial;

this.bldUpdate = bldUpdate;

}

 

function initialize() {

if (this.select_str =='') {

for(var i=0;i<document.forms[this.formname][this.selname].options.length;i++) {

this.selectArr = document.forms[this.formname][this.selname].options;

this.select_str += document.forms[this.formname][this.selname].options.value+":"+

document.forms[this.formname][this.selname].options.text+",";

}

}

else {

var tempArr = this.select_str.split(',');

for(var i=0;i<tempArr.length;i++) {

var prop = tempArr.split(':');

this.selectArr = new Option(prop[1],prop[0]);

}

}

return;

}

function bldInitial() {

this.initialize();

for(var i=0;i<this.selectArr.length;i++)

document.forms[this.formname][this.selname].options = this.selectArr;

document.forms[this.formname][this.selname].options.length = this.selectArr.length;

return;

}

 

function bldUpdate() {

var str = document.forms[this.formname][this.textname].value.replace('^\\s*','');

if(str == '') {this.bldInitial();return;}

this.initialize();

var j = 0;

pattern1 = new RegExp("^"+str,"i");

for(var i=0;i<this.selectArr.length;i++)

if(pattern1.test(this.selectArr.text))

document.forms[this.formname][this.selname].options[j++] = this.selectArr;

document.forms[this.formname][this.selname].options.length = j;

if(j==1){

document.forms[this.formname][this.selname].options[0].selected = true;

document.forms[this.formname][this.selname].options[0].text;

}

}

function setUp() {

obj1 = new SelObj('menuform','itemlist','entry');

obj1.bldInitial();

}

//-->

</SCRIPT>

 

<CENTER>

<FORM name=menuform

onsubmit="java script:window.location = document.menuform.itemlist.options[document.menuform.itemlist.selectedIndex].val

ue;return false;"><FONT

color=black face="verdana, courier, arial" size=2>digire uma letra para buscar

um item<BR>exemplo:ceu</FONT> <BR><INPUT name=entry

onkeyup=java script:obj1.bldUpdate(); size=30> <BR><SELECT name=itemlist size=5>

<OPTION value=pagina.html>a<OPTION value=pagina.html>antes<OPTION

value=pagina.html>avião<OPTION value=pagina.html>agua<OPTION

value=pagina.html>antes<OPTION value=pagina.html>avião<OPTION

value=pagina.html>agilizar<OPTION value=pagina.html>c<OPTION

value=pagina.html>e<OPTION value=pagina.html>ceu<OPTION

value=pagina.html>ce<OPTION value=pagina.html>outras palavras</OPTION></SELECT>

</FORM></CENTER></BODY></HTML>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.