Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                  <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>
              
            
!

CSS

              
                
              
            
!

JS

              
                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
What's a functional programmer's favorite animal? A lamb, duh!

Console