26. august 2008 - 13:03Der er
7 kommentarer og 2 løsninger
Hvordan laver man en Combobox med search funktion
Hej Eksperter.
Jeg har lidt problemer med at finde ud af hvordan jeg laver en combobox med search funktion. Jeg har en txt fil jeg læser med array og som skal smides ind i en combobox. Det er intet problem. men jeg vil meget gerne have den sådan at hvis man fx. skriver "yar" så kommer alle dem der starter med yar*. Det skal være til html eller asp vil jeg tro.
Er i med på hvad jeg mener?
I må meget gerne skrive hvis i ved noget om hvor jeg evt kan læse noget om det.
Teknologi, AI og forretning er i centrum på Computerworlds Cloud og AI Festival i København d. 18. og 19. september. Se hele programmet for den store konference om strategisk brug af Cloud og AI på: www.cloud-festival.dk
function handleFocus(event) { e = getEvent(event); eL = getEventElement(e); if (focEl = isWithinNode(eL,null,"wickEnabled",null,null)) { if (!siw || (siw && !siw.selectingSomething)) processSmartInput(focEl); } }//handleFocus()
function handleBlur(event) { e = getEvent(event); eL = getEventElement(e); if (blurEl = isWithinNode(eL,null,"wickEnabled",null,null)) { if (siw && !siw.selectingSomething) hideSmartInputFloater(); } }//handleBlur()
function handleClick(event) { e2 = getEvent(event); eL2 = getEventElement(e2); if (siw && siw.selectingSomething) { selectFromMouseClick(); } }//handleClick()
function handleMouseOver(event) { e = getEvent(event); eL = getEventElement(e); if (siw && (mEl = isWithinNode(eL,null,"matchedSmartInputItem",null,null))) { siw.selectingSomething = true; selectFromMouseOver(mEl); } else if (isWithinNode(eL,null,"siwCredit",null,null)) { siw.selectingSomething = true; }else if (siw) { siw.selectingSomething = false; } }//handleMouseOver
function showSmartInputFloater() { if (!siw.floater.style.display || (siw.floater.style.display=="none")) { if (!siw.customFloater) { x = findElementPosX(siw.inputBox); y = findElementPosY(siw.inputBox) + siw.inputBox.offsetHeight; //hack: browser-specific adjustments. if (!siw.isGecko && !siw.isWinIE) x += 8; if (!siw.isGecko && !siw.isWinIE) y += 10; siw.floater.style.left = x; siw.floater.style.top = y; } else { //you may //do additional things for your custom floater //beyond setting display and visibility } siw.floater.style.display="block"; siw.floater.style.visibility="visible"; } }//showSmartInputFloater()
function hideSmartInputFloater() { if (siw) { siw.floater.style.display="none"; siw.floater.style.visibility="hidden"; siw = null; }//siw exists }//hideSmartInputFloater
function processSmartInput(inputBox) { if (!siw) siw = new smartInputWindow(); siw.inputBox = inputBox;
classData = inputBox.className.split(" "); siwDirectives = null; for (i=0;(!siwDirectives && classData[i]);i++) { if (classData[i].indexOf("wickEnabled") != -1) siwDirectives = classData[i]; }
function simplify(s) { return s.toLowerCase().replace(/^[ \s\f\t\n\r]+/,'').replace(/[ \s\f\t\n\r]+$/,''); //.replace(/[Ž,,,‘,\u00E9,\u00E8,\u00EA,\u00EB]/gi,"e").replace(/[ˆ,‰,\u00E0,\u00E2]/gi,"a"). }//simplify
function getUserInputToMatch(s) { a = s; fields = s.split(","); if (fields.length > 0) a = fields[fields.length - 1]; return a; }//getUserInputToMatch
function getUserInputBase() { s = siw.inputBox.value; a = s; if ((lastComma = s.lastIndexOf(",")) != -1) { a = a.replace(/^(.*\,[ \r\n\t\f\s]*).*$/i,'$1'); } else a = ""; return a; }//getUserInputBase()
re1m = new RegExp("^([ \"\>\<\-]*)("+userInput+")","i"); re2m = new RegExp("([ \"\>\<\-]+)("+userInput+")","i"); re1 = new RegExp("^([ \"\}\{\-]*)("+userInput+")","gi"); re2 = new RegExp("([ \"\}\{\-]+)("+userInput+")","gi");
for (i=0,j=0;(i<pointerToCollectionToUse.length);i++) { displayMatches = ((!standalone) && (j < siw.MAX_MATCHES)); entry = pointerToCollectionToUse[i]; mEntry = simplify(entry); if (!standalone && (mEntry.indexOf(userInput) == 0)) { userInput = userInput.replace(/\>/gi,'\\}').replace(/\< ?/gi,'\\{'); re = new RegExp("(" + userInput + ")","i"); if (displayMatches) { siw.matchCollection[j] = new smartInputMatch(entry, mEntry.replace(/\>/gi,'}').replace(/\< ?/gi,'{').replace(re,"<b>$1</b>")); } tempCollection[j] = entry; j++; } else if (mEntry.match(re1m) || mEntry.match(re2m)) { if (!standalone && displayMatches) { siw.matchCollection[j] = new smartInputMatch(entry, mEntry.replace(/\>/gi,'}').replace(/\</gi,'{').replace(re1,"$1<b>$2</b>").replace(re2,"$1<b>$2</b>")); } tempCollection[j] = entry; j++; } }//loop thru collection if (siw) { siw.lastUserInput = userInput; siw.revisedCollection = tempCollection.join(",").split(","); collectionIndex[userInput] = tempCollection.join(",").split(","); } if (standalone || siw.buildIndex) { collectionIndex[uifc] = tempCollection.join(",").split(","); if (siw) siw.buildIndex = false; } }//runMatchingLogic
function setSmartInputData() { if (siw) { orgUserInput = siw.inputBox.value; orgUserInput = getUserInputToMatch(orgUserInput); userInput = orgUserInput.toLowerCase().replace(/[\r\n\t\f\s]+/gi,' ').replace(/^ +/gi,'').replace(/ +$/gi,'').replace(/ +/gi,' ').replace(/\\/gi,'').replace(/\[/gi,'').replace(/\(/gi,'').replace(/\./gi,'\.').replace(/\?/gi,''); if (userInput && (userInput != "") && (userInput != '"')) { runMatchingLogic(userInput); }//if userinput not blank and is meaningful else { siw.matchCollection = null; } }//siw exists ... uhmkaaayyyyy }//setSmartInputData
function getSmartInputBoxContent() { a = null; if (siw && siw.matchCollection && (siw.matchCollection.length > 0)) { a = ''; for (i = 0;i < siw.matchCollection.length; i++) { selectedString = siw.matchCollection[i].isSelected ? ' selectedSmartInputItem' : ''; a += '<p class="matchedSmartInputItem' + selectedString + '">' + siw.matchCollection[i].value.replace(/\{ */gi,"<").replace(/\} */gi,">") + '</p>'; }// }//siw exists return a; }//getSmartInputBoxContent
function modifySmartInputBoxContent(content) { //todo: remove credits 'cuz no one gives a shit ;] - done siw.floaterContent.innerHTML = '<div id="smartInputResults">' + content + (siw.showCredit ? ('') : '') +'</div>'; siw.matchListDisplay = document.getElementById("smartInputResults"); }//modifySmartInputBoxContent()
function selectFromMouseOver(o) { currentIndex = getCurrentlySelectedSmartInputItem(); if (currentIndex != null) deSelectSmartInputMatchItem(currentIndex); newIndex = getIndexFromElement(o); selectSmartInputMatchItem(newIndex); modifySmartInputBoxContent(getSmartInputBoxContent()); }//selectFromMouseOver
function selectFromMouseClick() { activateCurrentSmartInputMatch(); siw.inputBox.focus(); hideSmartInputFloater(); }//selectFromMouseClick
function getIndexFromElement(o) { index = 0; while(o = o.previousSibling) { index++; }// return index; }//getIndexFromElement
function getCurrentlySelectedSmartInputItem() { answer = null; for (i = 0; ((i < siw.matchCollection.length) && !answer) ; i++) { if (siw.matchCollection[i].isSelected) answer = i; }// return answer; }//getCurrentlySelectedSmartInputItem
function selectSmartInputMatchItem(index) { siw.matchCollection[index].isSelected = true; }//selectSmartInputMatchItem()
function deSelectSmartInputMatchItem(index) { siw.matchCollection[index].isSelected = false; }//deSelectSmartInputMatchItem()
function selectNextSmartInputMatchItem() { currentIndex = getCurrentlySelectedSmartInputItem(); if (currentIndex != null) { deSelectSmartInputMatchItem(currentIndex); if ((currentIndex + 1) < siw.matchCollection.length) selectSmartInputMatchItem(currentIndex + 1); else selectSmartInputMatchItem(0); } else { selectSmartInputMatchItem(0); } modifySmartInputBoxContent(getSmartInputBoxContent()); }//selectNextSmartInputMatchItem
//note: instruct users to the fact that no commas should be present in entries. //it would make things insanely messy. //this is why i'm filtering commas here: for (x=0;x<collection.length;x++) { collection[x] = collection[x].replace(/\,/gi,''); }//
beklager det var mig der var lidt for hurtig din txt fil skal i dette script ligge samme sted som asp filen - ellers retter du til hvor du henter den - og jeg forventer her at det er tekst adskilt af komma.
Set fso = Server.CreateObject("Scripting.FileSystemObject") Set fileObj = fso.getFile(server.mappath("ministerier.txt")) 'her henter du filen Set txtStream = fileObj.OpenAsTextStream(1, -2) do while( NOT txtStream.AtEndOfStream ) strTxt = txtStream.ReadLine 'her læser du linie for linie auto_valg = auto_valg & strTxt 'her samler du linierne loop auto_valg = replace(auto_valg,",","','") 'her replacer du komma med anførselstegn komma anførselstegn auto_valg = "'"&auto_valg&"'" 'her sætter du anførselstegn i start og slut
'så sætter du dit auto_valg ned i collection som her %>
function handleFocus(event) { e = getEvent(event); eL = getEventElement(e); if (focEl = isWithinNode(eL,null,"wickEnabled",null,null)) { if (!siw || (siw && !siw.selectingSomething)) processSmartInput(focEl); } }//handleFocus()
function handleBlur(event) { e = getEvent(event); eL = getEventElement(e); if (blurEl = isWithinNode(eL,null,"wickEnabled",null,null)) { if (siw && !siw.selectingSomething) hideSmartInputFloater(); } }//handleBlur()
function handleClick(event) { e2 = getEvent(event); eL2 = getEventElement(e2); if (siw && siw.selectingSomething) { selectFromMouseClick(); } }//handleClick()
function handleMouseOver(event) { e = getEvent(event); eL = getEventElement(e); if (siw && (mEl = isWithinNode(eL,null,"matchedSmartInputItem",null,null))) { siw.selectingSomething = true; selectFromMouseOver(mEl); } else if (isWithinNode(eL,null,"siwCredit",null,null)) { siw.selectingSomething = true; }else if (siw) { siw.selectingSomething = false; } }//handleMouseOver
function showSmartInputFloater() { if (!siw.floater.style.display || (siw.floater.style.display=="none")) { if (!siw.customFloater) { x = findElementPosX(siw.inputBox); y = findElementPosY(siw.inputBox) + siw.inputBox.offsetHeight; //hack: browser-specific adjustments. if (!siw.isGecko && !siw.isWinIE) x += 8; if (!siw.isGecko && !siw.isWinIE) y += 10; siw.floater.style.left = x; siw.floater.style.top = y; } else { //you may //do additional things for your custom floater //beyond setting display and visibility } siw.floater.style.display="block"; siw.floater.style.visibility="visible"; } }//showSmartInputFloater()
function hideSmartInputFloater() { if (siw) { siw.floater.style.display="none"; siw.floater.style.visibility="hidden"; siw = null; }//siw exists }//hideSmartInputFloater
function processSmartInput(inputBox) { if (!siw) siw = new smartInputWindow(); siw.inputBox = inputBox;
classData = inputBox.className.split(" "); siwDirectives = null; for (i=0;(!siwDirectives && classData[i]);i++) { if (classData[i].indexOf("wickEnabled") != -1) siwDirectives = classData[i]; }
function simplify(s) { return s.toLowerCase().replace(/^[ \s\f\t\n\r]+/,'').replace(/[ \s\f\t\n\r]+$/,''); //.replace(/[Ž,,,‘,\u00E9,\u00E8,\u00EA,\u00EB]/gi,"e").replace(/[ˆ,‰,\u00E0,\u00E2]/gi,"a"). }//simplify
function getUserInputToMatch(s) { a = s; fields = s.split(","); if (fields.length > 0) a = fields[fields.length - 1]; return a; }//getUserInputToMatch
function getUserInputBase() { s = siw.inputBox.value; a = s; if ((lastComma = s.lastIndexOf(",")) != -1) { a = a.replace(/^(.*\,[ \r\n\t\f\s]*).*$/i,'$1'); } else a = ""; return a; }//getUserInputBase()
re1m = new RegExp("^([ \"\>\<\-]*)("+userInput+")","i"); re2m = new RegExp("([ \"\>\<\-]+)("+userInput+")","i"); re1 = new RegExp("^([ \"\}\{\-]*)("+userInput+")","gi"); re2 = new RegExp("([ \"\}\{\-]+)("+userInput+")","gi");
for (i=0,j=0;(i<pointerToCollectionToUse.length);i++) { displayMatches = ((!standalone) && (j < siw.MAX_MATCHES)); entry = pointerToCollectionToUse[i]; mEntry = simplify(entry); if (!standalone && (mEntry.indexOf(userInput) == 0)) { userInput = userInput.replace(/\>/gi,'\\}').replace(/\< ?/gi,'\\{'); re = new RegExp("(" + userInput + ")","i"); if (displayMatches) { siw.matchCollection[j] = new smartInputMatch(entry, mEntry.replace(/\>/gi,'}').replace(/\< ?/gi,'{').replace(re,"<b>$1</b>")); } tempCollection[j] = entry; j++; } else if (mEntry.match(re1m) || mEntry.match(re2m)) { if (!standalone && displayMatches) { siw.matchCollection[j] = new smartInputMatch(entry, mEntry.replace(/\>/gi,'}').replace(/\</gi,'{').replace(re1,"$1<b>$2</b>").replace(re2,"$1<b>$2</b>")); } tempCollection[j] = entry; j++; } }//loop thru collection if (siw) { siw.lastUserInput = userInput; siw.revisedCollection = tempCollection.join(",").split(","); collectionIndex[userInput] = tempCollection.join(",").split(","); } if (standalone || siw.buildIndex) { collectionIndex[uifc] = tempCollection.join(",").split(","); if (siw) siw.buildIndex = false; } }//runMatchingLogic
function setSmartInputData() { if (siw) { orgUserInput = siw.inputBox.value; orgUserInput = getUserInputToMatch(orgUserInput); userInput = orgUserInput.toLowerCase().replace(/[\r\n\t\f\s]+/gi,' ').replace(/^ +/gi,'').replace(/ +$/gi,'').replace(/ +/gi,' ').replace(/\\/gi,'').replace(/\[/gi,'').replace(/\(/gi,'').replace(/\./gi,'\.').replace(/\?/gi,''); if (userInput && (userInput != "") && (userInput != '"')) { runMatchingLogic(userInput); }//if userinput not blank and is meaningful else { siw.matchCollection = null; } }//siw exists ... uhmkaaayyyyy }//setSmartInputData
function getSmartInputBoxContent() { a = null; if (siw && siw.matchCollection && (siw.matchCollection.length > 0)) { a = ''; for (i = 0;i < siw.matchCollection.length; i++) { selectedString = siw.matchCollection[i].isSelected ? ' selectedSmartInputItem' : ''; a += '<p class="matchedSmartInputItem' + selectedString + '">' + siw.matchCollection[i].value.replace(/\{ */gi,"<").replace(/\} */gi,">") + '</p>'; }// }//siw exists return a; }//getSmartInputBoxContent
function modifySmartInputBoxContent(content) { //todo: remove credits 'cuz no one gives a shit ;] - done siw.floaterContent.innerHTML = '<div id="smartInputResults">' + content + (siw.showCredit ? ('') : '') +'</div>'; siw.matchListDisplay = document.getElementById("smartInputResults"); }//modifySmartInputBoxContent()
function selectFromMouseOver(o) { currentIndex = getCurrentlySelectedSmartInputItem(); if (currentIndex != null) deSelectSmartInputMatchItem(currentIndex); newIndex = getIndexFromElement(o); selectSmartInputMatchItem(newIndex); modifySmartInputBoxContent(getSmartInputBoxContent()); }//selectFromMouseOver
function selectFromMouseClick() { activateCurrentSmartInputMatch(); siw.inputBox.focus(); hideSmartInputFloater(); }//selectFromMouseClick
function getIndexFromElement(o) { index = 0; while(o = o.previousSibling) { index++; }// return index; }//getIndexFromElement
function getCurrentlySelectedSmartInputItem() { answer = null; for (i = 0; ((i < siw.matchCollection.length) && !answer) ; i++) { if (siw.matchCollection[i].isSelected) answer = i; }// return answer; }//getCurrentlySelectedSmartInputItem
function selectSmartInputMatchItem(index) { siw.matchCollection[index].isSelected = true; }//selectSmartInputMatchItem()
function deSelectSmartInputMatchItem(index) { siw.matchCollection[index].isSelected = false; }//deSelectSmartInputMatchItem()
function selectNextSmartInputMatchItem() { currentIndex = getCurrentlySelectedSmartInputItem(); if (currentIndex != null) { deSelectSmartInputMatchItem(currentIndex); if ((currentIndex + 1) < siw.matchCollection.length) selectSmartInputMatchItem(currentIndex + 1); else selectSmartInputMatchItem(0); } else { selectSmartInputMatchItem(0); } modifySmartInputBoxContent(getSmartInputBoxContent()); }//selectNextSmartInputMatchItem
//note: instruct users to the fact that no commas should be present in entries. //it would make things insanely messy. //this is why i'm filtering commas here: for (x=0;x<collection.length;x++) { collection[x] = collection[x].replace(/\,/gi,''); }//
ved ikke lige hvad du mener - den henter jo lige som den skal. Når man taster w henter den alle som starter med w
er dine linier i tekstfilen afsluttet med et komma ?
hvis ikke skal du sætte denne således
do while( NOT txtStream.AtEndOfStream ) strTxt = txtStream.ReadLine 'her læser du linie for linie if auto_valg = "" then auto_valg = strTxt 'her samler du linierne else auto_valg = auto_valg &","& strTxt 'her samler du linierne end if loop
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.