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.

            
              <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>
            
          
!
            
              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;
}
            
          
!
            
              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
🕑 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 ..................

Console