Jump to content

listbox search function help


davidolson

Recommended Posts

<script type="text/javascript">

function listBoxSearch(){
	
	var input =  document.getElementById('searchBox'),
        output = document.getElementById('listBoxF');
		
	if(input.value != ''){
		
		for (var i = 0; i < output.options.length; i++){
			
			if(output.options[i].text.substring(0, input.value.length).toUpperCase() == input.value.toUpperCase()){
				
				output.options[output.options.length] = new Option(output.options[i].innerHTML, output.options[i].text);
			
			}
		}
		
		
		if (output.options.length == 1) {
		    output.selectedIndex = 0;
		}
		 
   }

}
	
</script>

It dosen`t work. It should work like this[DEMO in attached filed]

listbox_with_keybord_search.htm

Link to comment
https://forums.phpfreaks.com/topic/291019-listbox-search-function-help/
Share on other sites

Hi David,

  We need more precision from you in describing your question.  "It doesn't work" doesn't tell us enough.

 

What specifically have you tried?

What sort of debugging have you attempted?

How did you determine it isn't working, and have you narrowed down the problem in any way?

 

There are some very important tools for figuring out javascript problems, that are available in the browsers.  I tend to use Firefox with firebug because that's what I know the best, but there are similar tools for chrome and IE.  What are you using?

 

There is also the well known testbed site http://jsfiddle.net that you can use to test and share your html/javascript coding iterations.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.