SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would i go about this? Part finder

    Hi,

    I'm a complete programming novice. I was hoping someone here could point me in the right direction on how to create a simple drop down list of vehicle manufacturers, which will then show another simple list of vehicle models, and finally on selecting the model, will show a table, text, list or whatever of suitable parts.

    Something like this would be ideal:

    http://www.ngkpartfinder.co.uk/motor...engine=&model=

    Unfortunately i don't have a clue there to start.

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Here is a nice tutorial to get you started:

    http://www.plus2net.com/php_tutorial..._down_list.php

    If you have more questions, I'm sure members here have the answers.

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Database is definately the way to go with this UNLESS you are only going to have a few makes and models and changes wont need to made often, in which case you could hardcode the makes and models and use Javascript to update the boxes.

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="en"><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    <title></title>
    <script type="text/javascript">
    var makes = new Array("BMW", "Ford");
    var models = new Array();models["BMW"] = new Array("318", "525", "650", "X5");models["Ford"] = new Array("Bronco", "Explorer", "Focus");
    function resetForm(theForm) { /* reset makes */  
     theForm.makes.options[0] = new Option("Please select a make", "");  
     for (var i=0; i<makes.length; i++) {    
      theForm.makes.options[i+1] = new Option(makes[i], makes[i]);  
     }  
     theForm.makes.options[0].selected = true;  /* reset models */  
     theForm.models.options[0] = new Option("Please select a model", "");  
     theForm.models.options[0].selected = true;
    }
    function updateModels(theForm) {  
     var make = theForm.makes.options[theForm.makes.options.selectedIndex].value;  
     var newModels = models[make];  
     theForm.models.options.length = 0;  
     theForm.models.options[0] = new Option("Please select a model", "");  
     for (var i=0; i<newModels.length; i++) {    
       theForm.models.options[i+1] = new Option(newModels[i], newModels[i]);  
     }  
     theForm.models.options[0].selected = true;
    }
    </script>
    </head>
    <body>
    <form name="autoSelectForm" action="" method="post">
    <select size="1" name="makes" onchange="updateModels(this.form)">
    </select><select size="1" name="models"></select>
    <input type="submit">
    </form>
    <script type="text/javascript">  
    resetForm(document.autoSelectForm);
    </script>
    <?php  
    $make 
    $_POST['makes'];  
    $model $_POST['models'];  
    if (
    $make && $model) {    
     echo 
    "<p>".$make." - ".$model."</p>";  
    }
    ?>
    </body>
    </html>
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •