Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter List

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
I am trying to get a list of names to be filtered as I type in.

The main page is as follows.

Code:
<html>
<head>
	<title>ajax test</title>
	<script src="js/prototype.js" type="text/javascript"></script>
	<script src="js/myAjax.js" type="text/javascript"></script>
</head>
	<body>
		<div id="namelist" name="namelist" style="height:350px;width:200px;"></div>
		<div>
		 Name: <input type="text" id="fltName" name="fltName" size="25" />
		</div>
		
		<script>
		 Event.observe(window, 'load', function() {
		  Event.observe('fltName', 'keyup', function(e){filterByName(e);});
		  filterByName('');//this initially populates the select list with ALL names...
		 });
		</script>
	</body>
</html>

The MyAjax.js contains the following:
Code:
function filterByName(strname){
 var params = new Hash();
 params.set('namestring',strname);
 params.set('actionval','getSelect');
 new Ajax.Updater('namelist','adminAjax.php',{parameters:params,method:'get'});
}

When there is no information in the text field, then I see the list of name, however it does not get filtered as I am typing.

Using firebug in Firefox, I think the issue is that the variable in the text field is not being sent across. Can anyone spot anything obviously wrong.
 
Bit more information:

I think the issue is with the following piece of code

Code:
Event.observe('fltName', 'keyup', function(e) {filterByName(e);});

In firebug the url shows as adminAjax.php?actionval=getSelect

Once I changes the line to:

Code:
Event.observe('fltName', 'keyup', function(){filterByName(document.getElementById(fltName));});

the url shows as adminAjax.php?namestring=&actionval=getSelect

The issue is getting the value in fltName

Again appreciate any help received.
 
Got it to work

Had to change it as follows.

Code:
Event.observe('fltName', 'keyup', function(){filterByName(document.getElementById('fltName').value);});
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top