hi all,

I'm new to PHP and Java script, but would like to get som experience with em'.

Im trying to make a search for a dropdown list, but it doesnt work?
It is based heavily on this code http://www.rgagnon.com/jsdetails/js-0089.html (wich works fine?)
I have testet to see if the searchSel() gets called, and it does. but the dropdown doesnt update?
If i hard code the option values it works, so I guess there are something wrong with the PHP? even tho the resulting source is identical to the hardcoded?

Any help you be apreciated

- hmortensen

<HTML><HEAD><SCRIPT type="text/javascript">
function searchSel() {
  var input=document.getElementById('realtxt').value.toLowerCase();
  var output=document.getElementById('realitems').options;
  for(var i=0;i<output.length;i++) {
    if(output[i].value.indexOf(input)==0){
      output[i].selected=true;
      }
    if(document.forms[0].realtxt.value==''){
      output[0].selected=true;
      }
  }
}
</SCRIPT>
</HEAD><BODY>
<FORM>
Search <input type="text" id="realtxt" onkeyup="searchSel()">
<SELECT id="realitems">
<OPTION value="">Select...
<?php
	$myMediaList = array();
	$f = file("c:\\ItemsList.txt");
	foreach ($f as $line) {
		if (strpos($line,'|') !== false) 
		{
			list($name, $location) = explode("|",$line);
			$myMediaList[trim($name)] = trim($location);
		}
	}
	foreach(array_keys($myMediaList) as $thekey)
	{
		echo '<OPTION value="', $myMediaList[$thekey], '">' , $thekey , "\r\n";
	}
?>
</SELECT>
</FORM></BODY></HTML>

The file "c:\\ItemsList.txt" contains:
Me|Programmer
Myself|PHP Programmer
Irene|Girl

Your code only works option value and text is same. and that to in small case
try with following
programmer|programmer
myself|myself
irene|irene

You need to modify your javascript function

commented: Short and to the point. +1

Your code only works option value and text is same. and that to in small case
try with following
programmer|programmer
myself|myself
irene|irene

You need to modify your javascript function

you are right.. I was focusing on the PHP as I didnt write the javascript, and expected that part to work..
I'll rewrite the javascript.

Thanks ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.