cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console