• Post Reply Bookmark Topic Watch Topic
  • New Topic

Building a three-level menu search from a CSV file  RSS feed

 
Jim Gund
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry if this is in the wrong topic...

I'm a total newbie with a lot of this stuff and trying to learn as I go.

I have a .csv file that I am trying to parse into a drop-down menu on a webpage.

Here is a sampling of data from the .csv file:

BIA-BB103-PT    PONTIAC>GRAND PRIX>2000-2003|
BIA-BB103-PT5   PONTIAC>GRAND PRIX>2000-2003|
BIA-BB112-PT    CADILLAC>CTS>2003-2007|
The first row is column headers.

I am trying to do a cascading menu, three levels.

The first level would be Make (Pontiac, Cadillac, etc.)
The second level would be Model (Grand Prix, CTS, etc.)
The third level would be Year (2000, 2001, 2002, and so on)

Based on the selections - it would then search and return a SKU (BIA-BB113-PT for example).

I'm new to a lot of this and tried what little I know but cannot get this to work, any help here would be appreciated.
 
Carey Brown
Bartender
Posts: 3009
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A csv file (comma separated variables) is normally taken to mean any text file whose fields are separated (delimited) by an agreed upon character. Typical delimiters include commas, spaces, tabs, semi-colons, and vertical pipe (|). You would need to choose a character that you can guarantee won't appear in the normal data text.

So your data might be better expressed as

An advantage of a csv file is that the individual fields can be accessed easily by using the String.split() method on each line. In this case it would look something like:

Edit: Note that using the argument to split as "|" won't work because the vertical pipe has a special meaning, therefore it needs to be "escaped", hence the double backslashes in front: "\\|".
 
Jim Gund
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I will give that a try!
 
Jim Gund
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way that I could hard-code the selctions in the first drop-down and have the selections change in the second depending on what they selected in the first?

For example:

Selected Pontiac in the first box, and the second box will change to present options for Bonneville, Grand Am, etc.

I'm really sorry, I'm sure that there is documentation on this somewhere online, I HAVE been searching but most of the examples are beyond my experience level.
 
Knute Snortum
Sheriff
Posts: 4081
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to say sorry, that's why we're here!

Finding Java documentation is an important part of being a programmer.  I often Google "java 8 <someSearchString>", or you can bookmark https://docs.oracle.com/javase/8/docs/api/index.html

Are you going to use MenuItem?  I don't see any way to preselect an item in the menu.  Probably the best way is to make it the first option.
 
Campbell Ritchie
Marshal
Posts: 55770
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please tell us the algorithm you are using for searching: no code permitted at this stage. Then let's see how we can improve that.
 
Carey Brown
Bartender
Posts: 3009
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While you are pondering an algorithm it would help us to help you if we had a better understanding of your skill level. Are you familiar with:
  • arrays
  • loops
  • creating classes
  • lists, e.g. ArrayList

  •  
    Jim Gund
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I understand the basic concept of creating an array, I think...

    [Acura, Audi, BMW, Chrysler]

    That would be an array...correct?
     
    Carey Brown
    Bartender
    Posts: 3009
    46
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well, that might be a way to display an array, but how would you create that array?
     
    Jim Gund
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Looking around on the web, it looks like the first array would be something similiar to this:

    var makes = ["ACURA", "AUDI", "BMW", "BUICK", "CADILLAC", "CHEVROLET", "CHRYSLER", "DODGE", "FORD", "GMC", "HONDA", "HYUNDAI", "HUMMER", "INFINITI", "ISUZU", "JAGUAR", "JEEP", "KIA", "LAND ROVER", "LEXUS", "LINCOLN", "MAZDA", "MERCURY", "MINI", "MITUSBISHI", "NISSAN", "OLDSMOBILE", "PLYMOUTH", "PONTIAC", "PORSCHE", "SAAB", "SATURN", "SCION", "SMART", "SUBARU", "SUZUKI", "TOYOTA", "VOLKSWAGEN", "VOLVO"];

    I would use that to fill out the the first drop-down?
    Then I would need something to link the selections (Acura, Audi, etc...) to the models in the second drop-down, correct?
     
    Jim Gund
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok, so, looking over and scavenging code from another site and modifying it, this is what I came up with.

    <html>
    <head>
    <style>

    </style>
    </head>
    <body>

    <select id="select make">
        <option>Select Make</option>
    </select>

    <script>
    var select = document.getElementById("select make");
    var options = ["ACURA", "AUDI", "BMW", "BUICK", "CADILLAC", "CHEVROLET", "CHRYSLER", "DODGE", "FORD", "GMC", "HONDA", "HYUNDAI", "HUMMER", "INFINITI", "ISUZU", "JAGUAR", "JEEP", "KIA", "LAND ROVER", "LEXUS", "LINCOLN", "MAZDA", "MERCURY", "MINI", "MITUSBISHI", "NISSAN", "OLDSMOBILE", "PLYMOUTH", "PONTIAC", "PORSCHE", "SAAB", "SATURN", "SCION", "SMART", "SUBARU", "SUZUKI", "TOYOTA", "VOLKSWAGEN", "VOLVO"];
    for(var i = 0; i < options.length; i++) {
        var opt = options[i];
        var el = document.createElement("option");
        el.textContent = opt;
        el.value = opt;
        select.appendChild(el);
    }
    </script>

    </body>
    </html>
     
    Jim Gund
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok, so, I've come up with this - all the makes are listed, only Acura Models are present in the second dropdown.  I'd like to add the rest of the models for the different makes, how do tie a model to a make.
    If the person selects Acura, it will only display Acura models in the second drop-down.
    Again, apologies, its actually quite humbling to realize just how little I know when it comes to making these computer-machines do what you want to do.

     
    salvin francis
    Bartender
    Posts: 1612
    36
    Eclipse IDE Google Web Toolkit Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It is kind of off-topic, but I am curious. Why are you using a properties file model vs a hierarchical based model such as Json or XML ?
    You are creating your own algorithm to parse it using pipe as your delimiter for separation. What if the data itself had a pipe ?
     
    Jim Gund
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Because, I dont know what I'm doing.  LOL.

    Thats literally the long and short of it.  Total amateur hour here.
     
    Knute Snortum
    Sheriff
    Posts: 4081
    112
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm confused.  Do you want to program this in Java or JavaScript?  They are completely different things.  You've posted in the Beginning Java forum but the code you posted is JavaScript.
     
    Jim Gund
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Is there a way to change the topic?
     
    Knute Snortum
    Sheriff
    Posts: 4081
    112
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So I'm assuming you do want JavaScript.  I'll move the topic to a new forum.
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!