Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

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

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.

HTML

              
                <h1>Prefill Machine</h1>

<p>
  <button id="prefill">Refresh Random Data</button>
</p>

<form action="#0" id="form">
  
  <div>
    <label for="name">Name</label>
    <input type="text" name="name" id="name" placeholder="Digby Coyier" required>
  </div>
  
  <div>
    <label for="email">Email</label>
    <input type="email" name="email" id="email" placeholder="[email protected]" required>
  </div>
  
  <div>
    <label for="name">Username</label>
    <input type="text" name="username" id="username" placeholder="digby2007" required>
  </div>
  
  <div>
    <label for="name">Password</label>
    <input type="password" name="pw" id="pw" required>
  </div>
  
  <div>
    <label for="name">Repeat</label>
    <input type="password" name="pw-repeat" id="pw-repeat" required>
  </div>
  

  <fieldset>
    <legend>Radio Choice</legend>

    <div class="choice-group">
      <label class="radio-label" for="radio-choice-1">Choice 1</label>
      <input type="radio" name="radio-choice" id="radio-choice-1" value="choice-1" />

      <label class="radio-label" for="radio-choice-2">Choice 2</label>
      <input type="radio" name="radio-choice" id="radio-choice-2" value="choice-2" />
    </div>
  </fieldset>

  <div>
    <label for="select-choice">Select Choice</label>
    <div class="choice-group">
      <select name="select-choice" id="select-choice">
        <option value="Choice 1">Choice 1</option>
        <option value="Choice 2">Choice 2</option>
        <option value="Choice 3">Choice 3</option>
      </select>
    </div>
  </div>

  <div>
    <label for="message">Message</label>
    <textarea cols="40" rows="8" name="message" id="message"></textarea>
  </div>
  
  <div>
    <label for="cc">Credit Card #</label>
    <input type="text" name="cc" id="cc" placeholder="4242 4242 4242 4242" required>
  </div>

  <div>
    <label for="exp-1">Expiration <span class="screen-reader">Month</span></label>
    <input class="very-short" type="number" name="exp-1" id="exp-1" placeholder="08" min="1" max="12">
    <label for="exp-2" class="screen-reader">Expiration Year</label>
    <input type="number" name="exp-2" class="very-short" id="exp-2" placeholder="16" min="14">
  </div>

  <div>
    <label for="exp-1">CVV</label>
    <input class="short" type="text" name="cvv" id="cvv" placeholder="123">
  </div>
  
  <div>
    <label for="name">Address</label>
    <input type="text" class="long" name="address" id="address" placeholder="123 Super Street">
  </div>
  
  <div>
    <label for="city">&nbsp;<span class="screen-reader">City<span></label>
    <input type="text" name="city" id="city" class="medium"  placeholder="Milwaukee">
    <label for="state" class="screen-reader">State</label>
    <input type="text" name="state" class="very-short" id="state" placeholder="WI">
    <label for="zip" class="screen-reader">Zip</label>
    <input type="text" name="zip" class="short" id="zip" placeholder="55555" pattern="(\d{5}([\-]\d{4})?)" required>
  </div>
  
  <div>
    <label for="agree-terms">Agree?</label>
    <div class="choice-group">
      <input type="checkbox" name="agree-terms" id="agree-terms">
    </div>
  </div>

  <div>
    <input type="submit" value="Submit" id="submit-button">
  </div>
</form>  
              
            
!

CSS

              
                form {
  padding-top: 30px;
  min-width: 458px;
  > div,
  > fieldset {
    border: 0;
    padding: 0;
    margin: 0 0 8px 0;
    clear: both;
  }
  label,
  legend {
    float: left;
    width: 100px;
    padding: 7px 10px;
    &.radio-label {
      float: none;
      padding: 0;
    }
  }
  .choice-group {
    padding: 7px 10px 0 10px;
  }
  input[type=checkbox],
  input[type=radio] {
    margin-right: 10px;
  }
  input[type=text],
  input[type=email],
  input[type=password],
  input[type=number],
  textarea {
    width: 200px;
    border: 1px solid darken(tan, 20%);
    padding: 7px 10px;
    border-radius: 4px;
    outline: 0;
    &:focus {
      border-color: black;
    }
    &.short {
      width: 60px;
    }
    &.medium {
      width: 150px;
    }
    &.very-short {
      width: 40px;
    }
    &.long {
      width: 300px;
    }
  }
}

.screen-reader {
  position: absolute;
  top: -9999px;
  left: -9999px;
}

body {
  background: #E27C37;
  padding: 20px;
  font-size: small;
}
              
            
!

JS

              
                var runBookmarklet = function() {


/*==========  Code starts here, above is for demo to work inside CodePen  ==========*/

(function(win, doc, $) {

  'use strict';

  // Don't run script if jQuery isn't loaded
  if (typeof win.jQuery === 'undefined') {
    return;
  }

  var data, fillForm, FormData, len, _rand;

  // I like Chris's randomize function.  Lets use it here.
  _rand = function(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  };

  // Load FakerJS library
  $.getScript('//cdnjs.cloudflare.com/ajax/libs/Faker/0.7.2/MinFaker.js')
    .done(function() {
      fillForm();
    })
    .fail(function() {
      win.console.error('ERROR: FakerJS not loaded!');
    });




  /*==========  CREATE DATA OBJECT  ==========*/

  FormData = function(faker) {

    this.faker     = faker;

    this.randomWord = faker.Internet.domainWord();

    this.username  = 'fake_' + this.randomWord;
    this.username  += _rand(100,9999);

    // set this value to your password specifications
    this.password  = 'pass1234';

    this.name      = faker.Name.findName();

    this.address1  = faker.Address.streetAddress();
    this.city      = faker.Address.city();
    this.state     = faker.random.br_state_abbr();
    this.zip       = faker.Address.zipCode();

    // Chris's actual credit card number
    this.cc        = '4242 4242 4242 4242';
    this.exp1      = _rand(1,12);
    this.exp2      = _rand(14,22);
    this.cvv       = _rand(100,999);

  };


  FormData.prototype.randomizeSelect = function(el) {
    var $el = $(el);

    len  = $el.find('option').length - 1;

    $el.children('option')
      .prop('selected', false)
      .eq( _rand( 1,len + 1 ) )
      .prop('selected', true);
  };

  FormData.prototype.randomizeRadio = function(radios) {
    radios = radios.not('[type="hidden"]');
    len    = radios.length;

    radios
      .prop('checked', false)
      .eq( _rand( 0, len - 1 ) )
      .prop('checked', true);
  };

  FormData.prototype.randomizeParagraph = function(el) {
    $(el).val(this.faker.Lorem.sentence(5));
  };

  FormData.prototype.randomizeCheckbox = function(el) {
    var $el  = $(el);

    $el.prop('checked', false);

    if (_rand( 0,1 ) === 0) {
      $el.prop('checked', true);
    }
  };

  FormData.prototype.randomizeEmail = function(el) {
    $(el).val('chriscoyier+' + this.randomWord + '@gmail.com');
  };



  /*==========  FILL IN THE FORM  ==========*/

  fillForm = function() {
    data = new FormData(win.Faker);

    $('#name').val(data.name);
    $('#username').val(data.username);
    $('#cc').val(data.cc);
    $('#exp-1').val(data.exp1);
    $('#exp-2').val(data.exp2);
    $('#cvv').val(data.cvv);
    $('#address').val(data.address1);
    $('#city').val(data.city);
    $('#state').val(data.state);
    $('#zip').val(data.zip);
    $('#pw').val(data.password);
    $('#pw-repeat').val(data.password);

    data.randomizeRadio($('[name="radio-choice"]'));

    // Randomize all select boxes
    $('select').each(function() {
      data.randomizeSelect(this);
    });

    // Randomize all checkboxes
    $('input[type="checkbox"').each(function() {
      data.randomizeCheckbox(this);
    });

    // Randomize all textareas
    $('textarea').each(function() {
      data.randomizeParagraph(this);
    });

    // Randomize all emails
    $('input[type="email"').each(function() {
      data.randomizeEmail(this);
    });

  };

}(window, window.document, window.jQuery));


/*==========  EOF Bookmarklet Code. Below is for Codepen demo. ==========*/

};
runBookmarklet();
window.jQuery('#prefill').on('click', runBookmarklet);


              
            
!
999px

Console