css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
                <h1>Dynamic Select Statements</h1>
  <label for="event_region">Select Region</label>
  <select id="event_region" onchange="event_postalcode(this);">
    <option value="empty">Select a Continent</option>
    <option value="Channel Islands">Channel Islands</option>
    <option value="East Midlands">East Midlands</option>
    <option value="Greater London">Greater London</option>
    <option value="Isle of Man">Isle of Man</option>
                <option value="North East">North East</option>
                <option value="North West">North West</option>
                <option value="Northern Ireland">Northern Ireland</option>
                <option value="Scotland">Scotland</option>
                <option value="South East">South East</option>
                <option value="South West">South West</option>
                <option value="Wales">Wales</option>
                <option value="West Midlands">West Midlands</option>
                </select>
  <br/>
  <label for="county">Select a Region</label>
  <select id="event_postalcode">
    <option value="0">Select a Postalcode</option>
  </select>
            
          
!
            
              var postcodeLists = new Array(4);
postcodeLists["empty"] = ["Select a Region"];
postcodeLists["Channel Islands"] = ["Please Choose", "GY", "JE"];
postcodeLists["East Midlands"] = [
  "Please Choose",
  "CB",
  "CO",
  "DE",
  "DN",
  "IP",
  "LE",
  "LN",
  "NG",
  "NR",
  "PE",
  "S"
];
postcodeLists["Greater London"] = [
  "Please Choose",
  "BR",
  "CR",
  "DA",
  "E",
  "EC",
  "EN",
  "HA",
  "IG",
  "KT",
  "N",
  "NW",
  "RM",
  "SE",
  "SM",
  "SW",
  "TW",
  "UB",
  "W",
  "WC",
  "WD"
];
postcodeLists["Isle of Man"] = ["Please Choose", "IM"];
postcodeLists["North East"] = [
  "Please Choose",
  "DH",
  "DL",
  "HG",
  "HU",
  "LS",
  "NE",
  "SR",
  "TS",
  "WF",
  "YO"
];
postcodeLists["North West"] = [
  "Please Choose",
  "BB",
  "BO",
  "BL",
  "CA",
  "CH",
  "CW",
  "FY",
  "HX",
  "L",
  "LA",
  "M",
  "OL",
  "PR",
  "SK",
  "WA",
  "WN"
];
postcodeLists["Northern Ireland"] = ["Please Choose", "BT"];
postcodeLists["Scotland"] = [
  "Please Choose",
  "AB",
  "DD",
  "DG",
  "EH",
  "FK",
  "GH",
  "SI",
  "VK",
  "AK",
  "WK",
  "YM",
  "LP",
  "AP",
  "MT",
  "D",
  "ZE"
];
postcodeLists["South East"] = [
  "Please Choose",
  "AL",
  "BN",
  "CM",
  "CT",
  "GU",
  "HP",
  "LU",
  "ME",
  "MK",
  "OX",
  "PO",
  "RG",
  "RH",
  "SG",
  "SL",
  "SO",
  "SS",
  "TN"
];
postcodeLists["South West"] = [
  "Please Choose",
  "BA",
  "BH",
  "BS",
  "DT",
  "EX",
  "GL",
  "PL",
  "SN",
  "SP",
  "TA",
  "TQ",
  "TR"
];
postcodeLists["Wales"] = ["Please Choose", "CF", "LD", "LL", "NP", "SA", "SY"];
postcodeLists["West Midlands"] = [
  "Please Choose",
  "B",
  "CV",
  "DY",
  "HR",
  "NN",
  "ST",
  "TF",
  "WR",
  "WS",
  "WV"
];
/* event_postalcode() is called from the onchange event of a select element. 
 * param selectObj - the select object which fired the on change event. 
 */

function event_postalcode(selectObj) {
  // get the index of the selected option
  var idx = selectObj.selectedIndex;
  // get the value of the selected option
  var which = selectObj.options[idx].value;
  // use the selected option value to retrieve the list of items from the postcodeLists array
  cList = postcodeLists[which];
  // get the event_postalcode select element via its known id
  var cSelect = document.getElementById("event_postalcode");
  // remove the current options from the event_postalcode select
  var len = cSelect.options.length;
  while (cSelect.options.length > 0) {
    cSelect.remove(0);
  }
  var newOption;
  // create new options
  for (var i = 0; i < cList.length; i++) {
    newOption = document.createElement("option");
    newOption.value = cList[i]; // assumes option string and value are the same
    newOption.text = cList[i];
    // add the new option
    try {
      cSelect.add(newOption); // this will fail in DOM browsers but is needed for IE
    } catch (e) {
      cSelect.appendChild(newOption);
    }
  }
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console