Link to home
Start Free TrialLog in
Avatar of dwalton72
dwalton72

asked on

Dynamic Select List/Menu

I am trying to build a small "Amazon" style online catalogue.  I have approximately 3500 items and those are broken down into 130 categories and stored in an Access Database.  Because there are so many categories I would like to have a page where the user can have the option of Selecting a category from a dynamic select list.  After choosing the category they want, I would like for it to automatically bring up another dynamic page that has all of the products in that category.  I have the category and the product page designed.  I have the product page where I can list ALL of the items in the database BUT for some reason I can not select a category from the list and have it generate the products page that coincides with that certain category.  I've tried just about everything I can think of. I would love some advice on this matter.
Avatar of alexhogan
alexhogan

When your user selects the catagory from the drop down, do you have an onChange event for their selection?

You will need to have some even that fires in order to navigate to another page that will display the details.

For instance you could use the following javascript function that is one of the snippets in DW;
function redirect(URLString){
    location = URLString;
}

to redirect to the detail page.

Then in your selection page have something like;
<select name="myList">
    <option value="[id from the database]" onChange="redirect('myurl.php?cat=' + this.value)>[Catagory]</option>
</select>

This would, on change of the drop down, redirect to the page myurl.php, with a url parameter of cat=123 or some such.  On the detail page, myurl.php, you would trap the url parameter as a condition to  your query and then be able to display those items in that catagory.

Avatar of dwalton72

ASKER

Here is the code that I have right now on my "selection page."

<select name="select">
  <option value="null"><--Please Select a Category--></option>
  <%
While (NOT rsCategories.EOF)
%>
  <option value="<%=(rsCategories.Fields.Item("CategoryNumber").Value)%>"><%=(rsCategories.Fields.Item("Category").Value)%></option>
  <%
  rsCategories.MoveNext()
Wend
If (rsCategories.CursorType > 0) Then
  rsCategories.MoveFirst
Else
  rsCategories.Requery
End If
%>
</select>      

Will your code work on an asp page?  I noticed that your files are named ".php?"

The actual selection page is www.conjel.com/test/products.asp & category_list.asp
It will work with an asp page just as well as a php...

This is less code than I posted before, but you can easily change this to a function so you can call it anywhere.  Plus above I have the onChange code in the <option> tag and it should be in the <select> tag.  My mistake.

Put this in your <select> tag;
onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO"

You will need to have the drop down in a form.  In this case the form name is jump and the drop down is named menu.
The javascript calls that form and the dropdown and the index value and fires the form.
Your catagory values will be the url to the detail page(s).
Here is the code for my drop down box that is now on my selection page.
I'm not sure how I am supposed to manipulate the onChange code that you gave me.

           <form action="category_list.asp?SubGroup=<%=(rsGrocery.Fields.Item("SubGroup").Value)%>" method="post" name="form_categories" id="form_categories">
             <span class="style6"></span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="select_category" id="select_category">
onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO"
   <option value="null">Please Select a Category</option>
  <%
While (NOT rsCategories.EOF)
%>
  <option value="<%=(rsCategories.Fields.Item("CategoryNumber").Value)%>"><%=(rsCategories.Fields.Item("Category").Value)%></option>
  <%
  rsCategories.MoveNext()
Wend
If (rsCategories.CursorType > 0) Then
  rsCategories.MoveFirst
Else
  rsCategories.Requery
End If
%>
</select>
&nbsp;&nbsp;
<input type="submit" name="Submit" value="Go To Category">        
              </form>

So basically right now, I have a link from products.asp to category_list.asp.  I have not been able to capture the data from the selection page drop down menu and get that information to the category page.

I have 1 Db with 2 tables.  Conjel & Categories
Conjel contains
strItemCode
strItemDescription
Pack
Size
Retail
Sell
Subgroup

Categories contains
CategoryNumber
Category

CategoryNumber and Subgroup are the same and where the two tables are linked.

I want to choose the Category based on the CategoryNumber on the selection page and have it go to category_list.asp and show all of the information in the Conjel table based on the SubGroup/CategoryNumber that was selected from the drop down menu.

Sorry for being so ignorant.  Believe it or not, I thought I had it figured out.
No problem..,

The code that I gave you won't need a button on the bottom of the form to have it navigate to the other pages.  Once the user makes the selection it will automatically redirect to that page.


Try this;
<form action="category_list.asp?SubGroup=<%=(rsGrocery.Fields.Item("SubGroup").Value)%>" method="post" name="form_categories" id="form_categories">
             <span class="style6"></span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="select_category" id="select_category" onChange="location=document.form_categories.select_category.options[document.form_categories.select_category.selectedIndex].value;" value="GO">
   <option selected value="null">Please Select a Category</option>
  <%
  While NOT rsCategories.EOF
  %>
  <option value="<%=(rsCategories.Fields.Item("CategoryNumber").Value)%>"><%=(rsCategories.Fields.Item("Category").Value)%></option>
  <%
  rsCategories.MoveNext()
  Wend
If (rsCategories.CursorType > 0) Then
  rsCategories.MoveFirst
Else
  rsCategories.Requery
End If
%>
</select>    
</form>
Ok, I tried that code but it doesn't direct me to category_list.asp it just sends me to an error

the test URL looks like this when I try to select the second category in the list:

http://localhost/conjel/2

Shouldn't it go to

category_list.asp?    and then something ?


By the way, thanks for all your help.
You'll have to give me a better url than;
http://localhost/conjel/2

This only goes to your local machine.

Can you tell me what the error said?
Well that was it.  You can see at www.conjel.com/test/products.asp what happens when you selet a category.  

the only difference is it goes to www.conjel.com/test/2  instead of the localhost directory.

I see where you put the category_list.asp in the form action.  I'd tried that and had the same problem that I'm having now.  
Should I add code to the list or maybe to the category_list.asp page somewhere?
I see what's happening...

When I selected the first option it tried to go to the page;
http://www.conjel.com/test/1

Here's what you need to do;

In your loop put this;

<option value="category_list.asp?SubGroup=<%=(rsCategories.Fields.Item("CategoryNumber").Value)%>"><%=(rsCategories.Fields.Item("Category").Value)%></option>
I'm tryin to stop asking stupid questions but I have one more....

Where is my "loop?"
ASKER CERTIFIED SOLUTION
Avatar of alexhogan
alexhogan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Would it be appropriate for me to profess my love for you?  

Thanks so much.  That's perfect.