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

Auto Save

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

              
                <h3>Combined Login/Registration Form</h3>
<p>If usernames are not public, DO NOT DO THIS.</p>

<p>There are two things going on here.</p>
<ol>
  <li>Typing in a username that already exists gives an immediate reaction, changing the form. Only one form is necessary!</li>
  <li>When registering, you are only alerted of passwords not being equal if they are of the same length. (why is this not a thing?)</li>
</ol>

<p>In our imaginary database, "ShuckleFan3" is a user.</p>


<div id="formMessage" class="message"></div>

<form>
  <label>
    							Username (16 chars max)
							    <input id="login" type="text" name="login" placeholder="username (16 chars max)">
						  </label>
						  <label>
							    Password (6 chars +)
    							<input id="password" type="password" name="password" placeholder="password (6 chars +)">
  						</label>
						  <label>
							    Registering: Password again
							    <input id="password2" type="password" name="password2" placeholder="registering: password again">
							    <p id="userExists" style="display:none;">User Exists</p>
						  </label>
						  <button id="logRegButton">Login / Register</button>
</form>


<p>See a live example using this at http://www.story-ga.me/</p>
              
            
!

CSS

              
                label {
  display:inline-block;
  margin:0 1em 0 0;
  padding:.5em;
  background-color:#e0e0e0;
}

input, #userExists {
  display:block;
  	margin:0;
  	padding:.1em;
	  width:13em;
	  height:1.4em;
	  line-height:1.4em;
	  font-size:1em;
  border:1px solid #666;
  font-family:arial;
}
#userExists {
	  background-color:#3dff94;
}

.message {
  width:13em;
  height:2em;
  line-height:2em;
  padding:0 1em;
  margin-bottom:1em;
  background-color:lightblue;
  color:darkblue;
}
              
            
!

JS

              
                window.isRegistering = true;

function checkUsers(username)
{
  /* Checking the database for pretend right here. */
  if (username == "ShuckleFan3")
  {
    /* User Exists! No registration needed. */
    document.getElementById("password2").value = "";
			    document.getElementById("password2").style.display = "none";
			    document.getElementById("userExists").style.display = "block";
    window.isRegistering = false;
  }
  else
  {
    document.getElementById("userExists").style.display = "none";
    			document.getElementById("password2").style.display = "block";
    window.isRegistering = true;
  }
}

function checkPass(pass1, pass2)
{
  /* Not going to say anything if the user isn't finished typing. */
  if (pass1.length == pass2.length && window.isRegistering)
  {
    if (pass1 !== pass2)
      formMessage("The passwords are not the same.");
    else
      formMessage("");
  }
  else
    formMessage("");
}

function formMessage(message)
{
  			document.getElementById("formMessage").innerHTML = message;
}


/* Whenever a key is entered in the login field, we check (via ajax, etc) if that user already exists. */
document.getElementById("login").onkeyup=function(e){
  checkUsers(document.getElementById("login").value);
}
/* Whenever a key is entered in the password fields, we check (via ajax, etc if the passwords are the same) */
document.getElementById("password").onkeyup=function(e){
  checkPass(document.getElementById("password").value, document.getElementById("password2").value);
}
document.getElementById("password2").onkeyup=function(e){
  checkPass(document.getElementById("password").value, document.getElementById("password2").value);
}
/* You'd want to rate-limit these requests, of course. */
              
            
!
999px

Console