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.

              <div class="speech-bubble">
  <div id="bubble-title">
    AU/NZ - Multiple Country Address Form
  <div id="bubble-description">
    This example demonstrates the searching of an address from either AU or NZ and then the population of the address info into the address fields. The country select box is used to determine which address database is searched.

<form id="form-box" method="get">
  <div id="form-title">Customer Address</div>

  <div class="form-header">Select a country</div>
  <select class="country-select" id="country">
    <option value="AU" selected>Australia</option>
    <option value="NZ">New Zealand</option>
  <div id="au-form">
    <div class="form-header">Address Line 1</div>
    <input type="search" class="form-input" id="addrs_1" placeholder="Search address here..."></input>

    <div class="form-header">Address Line 2</div>
    <input type="search" class="form-input" id="addrs_2" autocomplete="off_1"></input>

    <div class="form-header">Suburb</div>
    <input type="text" class="form-input" id="suburb" autocomplete="off_1"></input>

    <div class="form-header">City/State</div>
    <input class="form-input" id="state_or_city" autocomplete="off_1"></input>

    <div class="form-header">Postcode</div>
    <input class="form-input" id="postcode" autocomplete="off_1"></input>

    <div class="form-header">Country</div>
    <input class="form-input" id="countryInput" autocomplete="off_1"></input>

  <input class="btn" type="submit" name="next" value="NEXT" onclick="#">
              @import url('https://fonts.googleapis.com/css?family=Open+Sans');

html, body {
  padding: 1em 1.5em;
  font-family: 'Open Sans', Arial, Helvetica, sans-serif;
  font-size: 15px;
  width: 650px;
  color: #6d6d6d;

.speech-bubble {
  position: relative;
  padding: 1.5em;
  border-radius: 10px;
  box-sizing: border-box;
  background: #eaf5fa;
  box-shadow: 0px 2px 15px 0 rgba(0, 0, 0, 0.4);
  margin-bottom: 40px

.speech-bubble::before {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  bottom: -2em;
  left: 42.5%;
  box-sizing: border-box;
  border: 1em solid black;
  border-color: transparent transparent #eaf5fa #eaf5fa;
  transform-origin: 0 0;
  transform: rotate(-45deg);
  box-shadow: -4px 4px 5px 0 rgba(0, 0, 0, 0.2);;
  z-index: 0;

#bubble-title {
  font-size: 1.3em;
  margin-bottom: 8px;

#form-box {
  height: content;
  padding: 2em 3.5em;
  border-top: 50px solid #E8E8E8;
  border-left: 2px solid #E8E8E8;
  border-right: 2px solid #E8E8E8;
  border-bottom: 2px solid #E8E8E8;

#form-title {
  font-size: 1.6em;
  padding-bottom: 6px;
  margin-bottom: 25px;
  border-bottom: 1.5px solid #E8E8E8;

.form-header {
  font-size: 16px;
  margin-bottom: 3px;

.form-input {
  width: 70%;
  height: 30px;
  font-size: 16px;
  padding-left: 6px;
  margin-bottom: 15px;

input[type=submit] {
  display: block;
  -webkit-appearance: button;
  font-size: 15px;
  width: 135px;
  height: 36px;
  margin-left: 254px;
  background-color: #E18988;
  color: #FFFFFF;
  border: none;
  border-radius: 3px;

/* Forces .form-input styles onto search type */
input[type=search] {
  -webkit-appearance: textfield;
  box-sizing: content-box;

select {
  background-color: white;
  border: thin solid #CCCCCC;
  margin-bottom: 15px;
  display: inline-block;
  color: #757575;
  border-radius: 0;
  font: inherit;
  font-size: 16px;
  height: 35px;
  padding: 0.4em 4.5em 0.5em 6px;

  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-appearance: none;
  -moz-appearance: none;

select.country-select {
    linear-gradient(45deg, transparent 50%, #757575 50%),
    linear-gradient(135deg, #757575 50%, transparent 50%),
    linear-gradient(to right, #CCCCCC, #CCCCCC);
    calc(100% - 20px) calc(1em),
    calc(100% - 15px) calc(1em),
    calc(100% - 2.5em) 0.4em;
    5px 5px,
    5px 5px,
    1px 1.5em;
  background-repeat: no-repeat;

select:-moz-focusring {
  color: transparent;
  text-shadow: 0 0 0 #000;
  var addressField = d.getElementById('addrs_1'),
      countrySelect = d.getElementById('country'),
      AFAPIkeys = {
      widgets = {
        AU: null,
        NZ: null

  function disableWidgets() {

  function setWidgetState(){
    disableWidgets(); // disable both widgets first
    var countryCode = countrySelect.options[countrySelect.selectedIndex].getAttribute('value'); 
    if (countryCode) {
      // selectively enable the right widget
  function autoFillFieldsByCountry(widget, countryCode) {
    switch (countryCode) {
      case 'AU':
        widget.on('result:select', function(fullAddress, metaData) {
          // You will need to update these ids to match those in your form
          document.getElementById('addrs_1').value = metaData.address_line_1;
          document.getElementById('addrs_2').value = metaData.address_line_2;
          document.getElementById('suburb').value = metaData.locality_name;
          document.getElementById('state_or_city').value = metaData.state_territory;
          document.getElementById('postcode').value = metaData.postcode;
          document.getElementById('countryInput').value = countrySelect.options[countrySelect.selectedIndex].text
      case 'NZ':
        widget.on('result:select', function(fullAddress, metaData) {
          var selected = new AddressFinder.NZSelectedAddress(fullAddress, metaData);
          // TO DO - You will need to update these ids to match those in your form
          document.getElementById('addrs_1').value = selected.address_line_1();
          document.getElementById('addrs_2').value = selected.address_line_2();
          document.getElementById('suburb').value = selected.suburb();
          document.getElementById('state_or_city').value = selected.city();
          document.getElementById('postcode').value = selected.postcode();
          document.getElementById('countryInput').value = countrySelect.options[countrySelect.selectedIndex].text

  function initAF(){
    widgets['AU'] = new AddressFinder.Widget(
    autoFillFieldsByCountry(widgets['AU'], 'AU')
    widgets['NZ'] = new AddressFinder.Widget(
    autoFillFieldsByCountry(widgets['NZ'], 'NZ')

    setWidgetState(); // Set the initial state for the form
    countrySelect.addEventListener('change', setWidgetState);

  function addScript(){
    var script = document.createElement('script');
    script.src = 'https://api.addressfinder.io/assets/v3/widget.js';
    script.async = true;
    script.onload = initAF;

  // Initialise


🕑 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 ..................