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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter Records based on a dropdown

Status
Not open for further replies.

ABinBoston

Programmer
Nov 6, 2001
22
US
I have an asp page that displays a list of employees and their departments.

NAME POSITION DEPT
Sally Ryan Manager Marketing
Jim Anyname Sales Mgr Sales


I'd like a way to have a dropdown in the header of the table allowing me to select a Name, then on change, filter the records to show only that employee. I'd also like to have a dropdown in the "position" header allowing me to select a position and show only employees in that category. Also, another dropdown listing the departments, then when a dept is selected, filter the records for the department.

Thanks! - AB
 
just need to call a javascript function onChange for that dropdown, and submit the form to itself, then grab the values back up when the page reloads and rebuild your sql:

<script language=javascript>
function submitMe(){
document.theForm.submit();
}
</script>

<form name=theForm method=post action=thisPage.asp>
<select name=name onChange=&quot;submitMe();&quot;>
.....
</select>
</form>

You'll need some way of detecting in the ASP code on this page whether or not it's a recursive load of the page. The simplest way to do this is to ask for the number of items in the form property of your request object:

if request.form.count > 0 then
'the load is a recursive one -- grab your
' users' values and rebuild the statement
else
'this is the first load of the page.
' load up your default sql and render the <select>s
' accordingly
end if

I keep threatening (myself) to write a FAQ that goes over the ins and outs of recursive forms, since it's such a useful method. Maybe I'll just do that this weekend sometime.

Meanwhile, if you hit any roadblocks, post back with some of your code, and we'll work them out.

hope that helps! :)
paul
penny.gif
penny.gif
 
I posted that FAQ, too, so if you have any trouble, head over to the FAQ section. I put up a working (albeit simplified) example.

:)
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top