0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by hmortensen
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

Votes + Comments
Short and to the point.
0

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 ;)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.