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

Quick-add: + add another resource

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.

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.

            
              <html>
  <head>
    <title>Tabbed Form</title>
  </head>
  <body>
    <form name="myform" onsubmit="return validateForm()">
      <ul>
        <li class="title">Who Are You?</li>
        <li class="fields">
          <label>*First Name:</label><br />
          <input id="first_name" class ="req" type ="text" /><br />
          <label>Middle Name:</label><br />
          <input id="middle_name" type ="text" /><br />
          <label>Last Name:</label><br />
          <input id="last_name" type ="text" /><br />
          <label>*Email:</label><br />
          <input id="email" class ="req" type ="text" /><br />
        </li>
        <li class="title">Where Are You?</li>
        <li class="fields">
          <label>City:</label><br />
          <input id="city" type ="text" /><br />
          <label>*State:</label><br />
          <input id="state" class ="req" type ="text" /><br />
          <label>Country:</label><br />
          <input id="country" type ="text" /><br />
        </li>
        <li class="title"> What Do You Do?</li>
        <li class="fields">
          <label>*Occupation:</label><br />
          <input id="occupation" class ="reg" type ="text" /><br />
          <label>Company:</label><br />
          <input id="company" type ="text" /><br />
          <label>Company Location:</label><br />
          <input id="location" type ="text" /><br />
        </li>
      </ul>
      <input type="submit" value="Submit Form" />
    </form>
  </body>
</html>
            
          
!
            
              body {
  width: 500px;
  margin: auto;
  text-align: center;
}

li {
  list-style: none;
} 

li.fields {
  margin: 0;
  padding: 1em 0;
} 

li.title {
  cursor: pointer;
  font-weight: bold;
  font-size: 1.5em;
  line-height: 2em;
  background: #e3e3e3;
  border-bottom: 1px solid #c5c5c5;
  border-top: 1px solid white;
} 

.hide { display: none; }


            
          
!
            
              $(document).ready(function() {
  $('li.fields').filter(':nth-child(n+4)').addClass('hide');
  
  $('ul').on('click', 'li.title', function(){
    $(this).next().slideDown(200).siblings('li.fields').slideUp(200);
  });
}); 

function validateForm() {
  for(var i = 0; i < myform.elements.length; i++) {
    if(myform.elements[i].className == "req" && myform.elements[i].value.length == 0) {
      alert('Please fill in all required fields');
      return false;
    }
  } 
  
  var email = document.getElementById('email').value;
  var atpos = email.indexOf('@');
  var dotpos = email.lastIndexOf('.');
  if (atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length) {
      alert('Please type a valid email address');
    return false;
      }
}
            
          
!
999px
Loading ..................

Console