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="container">
  
  <form id="theform" action="javascript:void(0);">
    
    <label for="about-yourself">About yourself:</label>
    <div class="ta-container">
      <textarea id="about-yourself" class="ta" name="about-yourself" rows="6" cols="75" data-maxchars="20" data-over="false" placeholder="Enter text here..." required></textarea>
      <div class="status-bar">
        <table>
          <tr><td>Characters:</td><td class="charcount"></td></tr>
          <tr><td class="remaining-label">Remaining:</td><td class="remaining"></td></tr>
        </table>
      </div>
    </div>
    
    <label for="your-proposal">Your proposal:</label>
    <div class="ta-container">
      <textarea id="your-proposal" class="ta" name="your-proposal" rows="6" cols="75" data-maxchars="25" data-over="false" placeholder="Enter text here..." required></textarea>
      <div class="status-bar">
        <table>
          <tr><td>Characters:</td><td class="charcount"></td></tr>
          <tr><td class="remaining-label">Remaining:</td><td class="remaining"></td></tr>
        </table>
      </div>
    </div>
    
    <label for="supporting-info">Supporting information:</label>
    <div class="ta-container">
      <textarea id="supporting-info" class="ta" name="supporting-info" rows="6" cols="75" data-maxchars="40" data-over="false" placeholder="Enter text here..." required></textarea>
      <div class="status-bar">
        <table>
          <tr><td>Characters:</td><td class="charcount"></td></tr>
          <tr><td class="remaining-label">Remaining:</td><td class="remaining"></td></tr>
        </table>
      </div>
    </div>
    
    <input id="submitbtn" type="submit" value="Submit">
    
  </form>
  
</div>
  
            
          
!
            
              /* Import Google Font */
@import url(https://fonts.googleapis.com/css?family=Nunito+Sans);

/* RESET */
* {
  padding: 0;
  margin: 0;
  font-size: 1em;
  box-sizing: border-box;
  font-family: 'Nunito Sans';
  color: hsl(0, 0%, 50%);
}

/* Containing areas */
.container { 
  width: 600px; 
  margin: 1em auto;
}
.ta-container {
  width: 100%;
  border: 1px solid hsl(0, 0%, 70%);
  border-radius: 0.25em;
  margin: 0.25em 0 1.5em;
}
.hasfocus {
  box-shadow: 0px 0px 6px hsl(210, 50%, 60%);
}

/* The textarea itself */
textarea { 
  padding: 0.25em;
  width: 100%;
  max-width: 100%;
  border: none;
  vertical-align:bottom;
  color: hsl(0, 0%, 50%);
  border-radius: 0.25em;
  outline: none;
}

/* The status bar */ 
.status-bar { 
  background: hsl(0, 0%, 90%);
  padding: 0.25em;
  text-align: right;
  font-family: sans-serif;
  font-size: 0.7em;
  width: 100%;
  color: hsl(0, 0%, 50%);
  border-radius: 0 0 0.25em 0.25em;
}
table { 
  width: auto;
  margin-left: auto;
  line-height: 1em;
}
.charcount, .remaining { 
  font-weight: bold;
}
.over {
  color: hsl(0, 80%, 60%);
}
/* The submit button */
#submitbtn {
  padding: 0.4em 1.2em;
  background: hsl(0, 0%, 100%);
  border: 1px solid hsl(0, 0%, 60%);
  color: hsl(0, 0%, 50%);
  border-radius: 0.25em;
}
#submitbtn:enabled:hover {
	background: hsl(0, 0%, 90%);
}
#submitbtn:enabled:active {
  background: hsl(0, 0%, 30%);
  color: hsl(0, 0%, 90%)
}
#submitbtn:disabled { 
  border: 1px solid hsl(0, 0%, 90%);
  color: hsl(0, 0%, 90%);
}
            
          
!
            
              /**
 * Functions to add/remove class on div.ta-container to emulate focus removed from textarea by CSS line 37 (outline:none)
 */
function setFocus(ta_container) {
  
  ta_container.classList.add('hasfocus')
  
}
function removeFocus(ta_container) {
  
  ta_container.classList.remove('hasfocus')
  
}

/**
 * Function to enable or disable #submitbtn
 * #submitbtn will be disabled if any of the textareas have data-over set 
 * to true due to exceeding the value specified in data-maxchars
 */
function setSubmitBtn() {
  
  var tas = theform.querySelectorAll('.ta')
  var disabled = false
  tas.forEach(function(ta) {
    
    if (ta.getAttribute('data-over') == 'true') {
      disabled = true
    }
    
  })
    
  if (disabled) {
    theform.querySelector('#submitbtn').disabled = true
  } else {
    theform.querySelector('#submitbtn').disabled = false
  }
  
}

/**
 * Function to count the characters in .ta and update .ta_container.statusbar
 * @param  {Obj} ta_container - the .ta-container element
 * @param  {Obj} ta - the .ta textarea element
 * @param  {Integer} maxLength - the max number of characters allowed in the .ta textarea element
 */
function countChars(ta_container, ta, maxLength) {
  
  var numChars = ta.value.length
  
  ta_container.querySelector('.charcount').innerHTML = numChars + '/' + maxLength
  ta_container.querySelector('.remaining').innerHTML = Math.abs( maxLength - numChars )
  
  if ( numChars > maxLength ) {
    
    ta_container.querySelector('.remaining-label').classList.add( 'over' )
    ta_container.querySelector('.remaining-label').innerHTML = 'Over by:'
    ta_container.querySelector('.remaining').classList.add( 'over' )
    ta.style.color = 'hsl(0, 80%, 60%)'
    ta.setAttribute('data-over', 'true')
    setSubmitBtn()
    
  } else {
    
    ta_container.querySelector('.remaining-label').classList.remove( 'over' )
    ta_container.querySelector('.remaining-label').innerHTML = 'Remaining:'
    ta_container.querySelector('.remaining').classList.remove( 'over' )
    ta.style.color = 'hsl(0, 0%, 50%)'
    ta.setAttribute('data-over', 'false')
    setSubmitBtn()
    
  }
  
}

/**
 * Initialisation function
 */
function initialise() {
  
  var ta_containers = theform.querySelectorAll('.ta-container')
  
  ta_containers.forEach( function(ta_container) {
    
    var ta = ta_container.querySelector('.ta')
    var maxLength = ta.getAttribute('data-maxchars')
    var numChars = ta.value.length
    
    ta_container.querySelector('.charcount').innerHTML = numChars + '/' + maxLength
    ta_container.querySelector('.remaining').innerHTML = maxLength - numChars
    
    ta.addEventListener( 'input', function() {
      countChars(ta_container, ta, maxLength)
    })
    
    ta.addEventListener( 'focus', function(){
      setFocus(ta_container)
    })
    
    ta.addEventListener( 'blur',  function(){
      removeFocus(ta_container)
    })
    
  })
  
}

/* Let's go! */
initialise()

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

Console