Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .hide { display: none ; }
- .show { display: inline ; }
- fieldset { border: #206ba4 1px solid; }
- fieldset legend { margin-top: -.4em; font-size: 20px; font-weight: bold; color: #206ba4; }
- fieldset fieldset { position: relative; margin-top: 25px; padding-top: 0.75em; background-color: #ebf4fa; }
- body { margin: 0; padding: 0; font-family : Verdana; font-size : 12px; text-align: center ; }
- #wrapper { margin: 40px auto 0 auto ; }
- #myFieldset { width: 213px ;}
- #area { margin: 20px ;}
- #area select {width: 75px ; float:left ;}
- #area label {display: block ; font-size: 1.1em; font-weight: bold; color: #000000;}
- #area #selection {display: block ; }
- #makes {margin: 5px ; }
- #models {margin: 5px ; }
- var cars = [
- {
- "makes" : "Honda",
- "models" : ['Accord','CRV','Pilot']
- },
- {
- "makes" :"Toyota",
- "models" : ['Prius','Camry','Corolla']
- } ] ;
- $(function() {
- vehicles = [] ;
- for(var i=0; i<cars.length; i++) {
- vehicles[cars[i].makes] = cars[i].models ;
- }
- var options = '' ;
- for (var i = 0; i < cars.length; i++) {
- options += '<option value="' + cars[i].makes + '">' + cars[i].makes + '</option>';
- }
- $("#make").html(options); // populate select box with array
- $("#make").bind("click",
- function() {
- $("#model").children().remove() ; // clear select box
- var options = '' ;
- for (var i = 0; i < vehicles[this.value].length; i++) {
- options += '<option value="' + vehicles[this.value][i] + '">' + vehicles[this.value][i] + '</option>';
- }
- $("#model").html(options); // populate select box with array
- $("#models").addClass("show") ;
- } // bind function end
- ); // bind end
- });
- <div id="wrapper">
- <fieldset id="myFieldset"><legend>Cars</legend>
- <fieldset id="area">
- <label>Select Make:</label>
- <div id="selection">
- <div id="makes">
- <select id="make"size="2"></select>
- </div>
- <div class="hide" id="models">
- <select id="model" size="3"></select>
- </div>
- </div>
- </fieldset>
- </fieldset>
- </div>
Add Comment
Please, Sign In to add comment