0

I've been trying to get a tutorial on creating a navigation for html Webpages via javascript or php I keep ending up puzzled.

What I want to achieve is a sort of website navigation on the site where a user can select Category via select box then subcategory gets populated via another select box and when user selects subcategory then subsubcategory gets populated via another select box then have a submit button that goes to the url.

Example: list of countries each with own unique html page. So if user hits submit he goes to the page obut if not then user can select state if state is selected then he goes to state unique html page and if not then he selects city then he can navigate to cities unique html page. So the structure looks like this:

Country/America.html - Country/State/Texas.html --Country/State/city/Texas-city.html

Any help or advice would be highly appreciated.

Junaid
  • 11
  • 4
  • Possible duplicate of [Populating One Select Box Based on the Selection in Another Select Box - JQuery?](http://stackoverflow.com/questions/5861090/populating-one-select-box-based-on-the-selection-in-another-select-box-jquery) – nerdlyist Aug 31 '16 at 13:44
  • Google "populate select based on another select" – nerdlyist Aug 31 '16 at 13:45
  • I know how to populate a select box via parent but I just don't know how to add a go to url via selected. – Junaid Aug 31 '16 at 14:04
  • get the values of the selects and build a path string. Then at the end of your selects add in a link or button which ever. It would be very similar to what you are doing for the selects. Or can they have a link at all levels? – nerdlyist Aug 31 '16 at 14:30
  • There's a link at all levels simply because each select has a unique html page. So for example on the site it will be like: research countries then user can select a country and just press submit to goto country page but if he doesn't he can select a state then go directly to state page. So it would be like a layered navigation via submit button i can't seem to get an example or tutorial anywhere on this. – Junaid Aug 31 '16 at 14:43
  • Here's an example I found on a car websites. www.autoguide.com and www.carandriver.com – Junaid Aug 31 '16 at 14:48
  • Do you have the selects working? If so put them in a form and then using the $_GET/$_POST parameters (depends on the form method) check to which level the selects are filled out. Based on that you will know which HTML to send. – nerdlyist Aug 31 '16 at 14:56
  • Yes the selects are working fine. I wish I knew exactly how to get that done but I'm going to try thank for your advice @nerdlyist – Junaid Aug 31 '16 at 15:44

1 Answers1

0

Lets assume you have this html page.

<form action="process.php" method="GET">
    <select name="set1">
        <option>Option...1</option>
        <option>Option...2</option>
        <option>Option...n</option>
    </select>
    <select name="set2">
        <option>Option...1</option>
        <option>Option...2</option>
        <option>Option...n</option>
    </select>
    <!-- ... as many as needed -->

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

now process.php could be something like

<?php
//Start backwards so you know the 
//last question answered
if(isset($_GET['set2'])){
    //Assuming the value is the same name as the html page.
    //If the path differs add the directories needed.
    header('Location: {$_GET['set2']}.html');
    exit;
}
else if(isset($_GET['set1'])){
    header('Location: {$_GET['set1']}.html');
    exit;
}
else {//..What to do when nothing was selected}
?>
nerdlyist
  • 2,842
  • 2
  • 20
  • 32
  • It doesn't seem to be taking me to the existing html page instead it takes me to the process.php page where it displays the code in the browser? Thanks for helping. – Junaid Aug 31 '16 at 18:27
  • Do the options have values set? That will be needed. You should leave your selects as they are. Update the process.php with all the possible names in $_GET ie the names of your selects. – nerdlyist Aug 31 '16 at 18:29
  • Yes all the options are there it returns process.php?Country=America, I will experiment but I get the idea on the process now – Junaid Aug 31 '16 at 18:34
  • Okay I figured it was the values that needed to be set properly I made a simple coding mistake thank you for you answer. – Junaid Aug 31 '16 at 20:23