Link to home
Start Free TrialLog in
Avatar of pcalabria
pcalabriaFlag for United States of America

asked on

I'd like suggestions for performing category searches on an HTML website.

Hello,
My website was created in Adobe Dreamweaver before the days for Wordpress and all the new technologies... its on a Windows server and uses classic asp, VBScript, and some javascript.
The database is MS SQLSERVER.  Each day I update the database to reflect new and deleted items but updating it in its entirety.  Parts that are sold on the website are emailed to my office, where they are entered each day along with walk-in-orders.

I would like to add a series of category searches..
for example... the first combo box would allow selecting a type..
a second combo box should then auto-populate and create a subtype.
and then a third and possible 4th to continue homing down until the end when I can display a list of parts that meet the specification...

For example.. if the part type selected is a Capacitor, we would also want to select the case size, value, voltage, tolerance, and so forth.

Once selected, I can do the database work to display the results.. but I'd like some help getting there.

I'm sure I can code this in Classic ASP... but I suspect there are much better ways to go... ASP would require loading a new page each time a new category is selected.

I'm hoping someone can suggest some code or a product I may be able to use to provide a better user experience...

Can anyone help? 
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Do you have a table that contains categories linked to part type? You need the backend setup before you can update the front end
Avatar of pcalabria

ASKER

Oh yes.. I have tables for cat1, cat2, cat3, cat4, and cat5.. not all are used..
So cat2 would be select cat2 from MyDB where cat1=<combobox selection> etc..

This is pretty easy in VBA.. but in Classic ASP you need to reload the page to get the server side processed..
This would mean each time you selected a new category... and people aren't patient enough for that these days..

ugh classic asp.. with no ajax.. I'd start thinking about upgrading the code on a page by page basis.
need to see your category structure and number of records here...
then I can suggest something...
and ASP, does not post page every time, you can easily use jQuery/ajax here...
old and new friends go together well :)
HainKurt...
I've attached a sample database with the category structure.. five fields cat1, cat2, ca3, cat4, cat5
All parts will have a Cat1.. and may have one or more of the other cat fields.

So the actual table structure would contain the fields.  Note that this table may have 500,000 records.
PartNumber, Price, Quantity, Cat1, Cat2, Cat3, Cat4, Cat5

The user needs to select a value from Cat1... which should cause a second combo box to appear... with only the cat2 values which correspond with the cat1 entry...

Example:
Select IC from the cat1 combo box...  the cat2 box appears and allows selecting Memory... which allows cat3 to appear where you can select DRAM, SDRAM, RAM, SRAM, Flash, EEPROM, etc

So let's say the user select IC, Memory, SRAM and then clicks the SEARCH_STOCK combo button
They would see a list of parts where cat1=IC, cat2=Memory, cat3=SRAM

Note that in the above example they would have the option of honing down further... by selecting a value for cat4..
or they could press the SHOW STOCK button at any time.
We would have to show them.. as a caption on the button or text box along side... how many parts match the selection.

So the button/textbox should read something like Show 53 Parts,
where 53 in this case would be the number of parts in my Inventory file that match all categories selected.

Thanks in advance for your help.  I've used some jquery and ajax controls before..


AttachedCatDemo.accdb


attached data doe not make sense to me...
are you saying, you have a table and it has some data + 5 Cat columns (Cat1,Cat2,...Cat5)
and there is no other place that holds these categories and relationship between those?

when I run this

SELECT distinct * from tblCategoryTool

Open in new window

I only see 607 records...
who/how this table is populated, any UI/screenshot that you can share that shows how data is entered to this table?
have a look at this...
not complete or may have errors, but this may work fine on your page, no post back, all in one shot
jQuery solution, custom made :)

https://jsfiddle.net/HainKurt/v16dnym5/
User generated image
Thanks. I'll check your link...

To be clear.. I gave you just the structure of the categories... There were other columns in the table which I are used to make to parts in our database.. but I deleted those before sending as the method that we match the categories is proprietary....

So think of the table I sent you as a linked row.. with the linked fields deleted... the structure of the categories is the same.. Thanks again..
Nice code.. looks great.. do I just copy this onto a single asp page?
I would also need to create a command button that performs a query based upon the selected values.
lbcat1.. lbcat2.. I guess that would be the names of the selected control..

If so looks straight forward.. I'll give it a try!
THANKS!!
you run a query and create the js array

I got that code with a query like this

SELECT DISTINCT "['" & Cat1 & "','" & Cat2 + "','" & Cat3 & "','" & Cat4 & "','" & Cat5 & "']," AS Cat15, *
FROM tblCategoryTool;

Open in new window


so, you just add jQuery.js to the asp page
and 5 combobox to the page
the rest is auto...
form is filled and you submit the page
and get the values of combos on server, do whatever you want...

no postback required...
HainKurt,
Sorry to take so long to response.... the new Windows feature update broke my computer...
Its working now.. hopefully Microsoft did something to fix the problem...

I'm still trying to understand how to use the code..
of course the HTML part make sense.. but I wasn't sure where to put the javascript/jquery stuff...
I thought it would go above the <head> tag.. but putting it there made a mess!
https://pccomponents.com/SearchByPartCategory.asp
Any suggestions other than finding a Javacscript and Jquery for Dummies book?

Windows feature update broke my computer...

you mean H2O update...
it crashed my PC as well, I needed to restore from backup last week...
still everyday, it tries to install .Net but fails (I already have this), which is required by H2O
Well I'm back up now...

Do you have any suggestions for what I did wrong?  I'm sure it has to do with connecting the jscript or javascript code.
you have to add script tags before and after the code...
that part is missing...

<script>
... code goes here
<script>

and that code should be between head tags, right now it is before head...

<html>
  ...
  <head>
  <script>
  ... code goes here
  <script>
</head>
<body>
...
</body>
</html>
HainKurt...
I believe I have the Javascript and JQuery code between script tags how, but still can't get it to work.
Note that I moved the link.. https://pccomponents.com/categorysearch.asp
Your continued help would be wonderful.
p.
ok, now, arrange your code like this

<script>
var Cats = [...];
console.log(Cats);
console.log(Cats.length);
function getCatValues(cn, c1, c2, c3, c4) {...};

$(document).ready(function(){
  //your jQuery starts here
  $("#lbCat1").empty();
  ...
  console.log(getCatValues(5)); 
});
</script>
HainKurt..

It's still not working.. I believe I implemented your changes correctly...
but without a way to test jquery or javascript and without speaking the language.. I'm so confusued!

Here's the current link..
https://pccomponents.com/categorysearch.asp
put the scripts to the top
User generated image
and after that, your code should follow...
right now, the code comes before jQuery and fails...
Great.. really making progress now!!
The line you highlighted was showing up in the code due to what Dreamweaver refers to as a template.. basically, an include file.. that I did not have access to... so I added the file a second time.. up higher in the code... and all seems to working now..

So now how do you suggest passing the values to another page.. so the database query can run?
Im expecting something like:

<form method="Post" action="mypagename.asp">

<input type="hidden" name="lblCat1" <value=<not sure what goes here">
<input type="hidden" name="lblCat2" <value=<not sure what goes here">
<input type="hidden" name="lblCat3" <value=<not sure what goes here">
<input type="hidden" name="lblCat4" <value=<not sure what goes here">
<input type="hidden" name="lblCat5" <value=<not sure what goes here">

<form input type="submit' value="">
</form>

Ist this the way to do it... and how do you grap that value???
no need for anything, just
<form method="Post" action="mypagename.asp">

... selects are here...

<form input type="submit' value="Search...">
</form>

Open in new window

then when user click Search button,
it will go to mypagename.asp, with all values posted, ready to get with

lbCat1=form("lbCat1")
lbCat2=form("lbCat2")
...

normally, you post to same page, leaving action=empty, so it posts to the same page
and in the same page, you check if page is submitted, like

if (form("lblCat1")<>"") then
... form is submitted
else
... initial code
end if
I'm working on the initial code section... and I'm missing something..
I changed the post to get so I could see what's going on..
I verified its not sending the variables.

My code:
<form method="post" action="CategorySearch.asp">
Cat 1: <select id="lbCat1"></select><br><br>
Cat 2: <select id="lbCat2"></select><br><br>
Cat 3: <select id="lbCat3"></select><br><br>
Cat 4: <select id="lbCat4"></select><br><br>
Cat 5: <select id="lbCat5"></select><br><br>
<input type="submit" value="Show Stock" >
</form>

ALSO-- in the resubmission code..
you use:
lbCat1=form("lbCat1") 

doesn't it need to be:
lbCat1=request.form("lbCat1") ??

Thanks
1. use method=post
it is set to get now...

and yes, it should be Request.Form

or you can use just Request("lblCat1"), it will check form vars first then query string...
Sorry for the confusion.. I switched to "get" so I could see where the code to set the lblcat values were actually being sent to the page.. and forgot to set it back to POST.

Still not working though..
I'm wondering whether it could have anything to do with this line which now appears twice in my code.  
<script src="/scripts/jquery-1.7.1.min.js" type="text/javascript"></script> 
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

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
I'm having a difficult time with this.. mostly because the company hosting our website does not seem to have iOS setup to return detailed messages.  difficult to trouble shoot 500 errors.

I spent some time to setup and learn fiddler but didn't give it enough time to figure it out.. if you do consulting and I can hire you to set up up and show me how to use it that would be great.

otherwise I'll let you know when I make any progress