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.

            
              <div class="container">
  <form onsubmit="sendEmail(event)">
    <legend>Contact Form</legend>
    <div id="alert-field" class="alert hidden">
      <p>Uh oh! Something went wrong!</p>
    </div>    
    <div class="form-group col-xs-6">
      <label for="name-field">Name</label>
      <input type="text" class="form-control" id="name-field" name="name-field" placeholder="Your name" required>
    </div>
    
    <div class="form-group col-xs-6">
      <label for="email-field">Email</label>
      <input type="email" class="form-control" id="email-field" name="email-field" placeholder="Email address" required>
    </div>
    
    <div id="subject-select" class="form-group col-xs-12">
      <label for="subject-field">Subject</label>
      <select class="form-control" name="subject-field" onchange="changeSubject(event)"  required>
        <option value="Consulting">#EdTech Consulting</option>
        <option value="Web Development">Web Development projects</option>
        <option value="Google Scripts">Google Apps Scripts</option>
        <option value="G Suite for Education">G Suite for Education Tools</option>
        <option value="Other">Other</option>
      </select>
    </div>
    
    <div id="hidden-other-subject" class="form-group col-xs-6 hidden">
      <label for="other-subject-field">Other</label>
      <input type="text" class="form-control" id="other-subject-field" name="other-subject-field" placeholder="Other subject" />
    </div>
    
    <div class="form-group col-xs-12">
      <label for="body-field">Message</label>
      <textarea id="body-field" name="body-field" class="form-control" placeholder="Type your message here" required></textarea>
    </div>
    
    <div class="form-group col-xs-12">
      <button type="submit" class="btn btn-primary btn-lg btn-block">Submit</button>  
    </div>
    
  </form>
</div>
            
          
!
            
              .container
  margin-top: 20px
  
  progress
    width: 100%
    
  
input
  transition: all 0.5s
            
          
!
            
              $(function() {
  $('.form-control').focus(formFocus);
});

function formFocus() {
  $('#alert-field')
    .removeClass()
    .addClass('hidden');
}

function sendEmail(e) {
  e.preventDefault();

  const POST_URL = '';

  const postRequest = {
    name: e.target['name-field'].value,
    email: e.target['email-field'].value,
    subject: e.target['other-subject-field'].value || e.target['subject-field'].value,
    body: e.target['body-field'].value
  };
  
  if(POST_URL) {
    $.post(POST_URL, JSON.stringify(postRequest))
      .then(res => {
      
        e.target.reset();
        $('#alert-field')
          .removeClass()
          .addClass(`alert alert-${res.code}`)
          .text(res.msg);
      });

    $('#alert-field')
      .removeClass()
      .html('<progress></progress>')
      .removeClass('hidden');
  } else {
    alert('You must set the POST_URL variable with your script ID');
  }

}

function changeSubject(e) {
  if(e.target.value === 'Other') {

    $('#subject-select').removeClass('col-xs-12')
      .addClass('col-xs-6');
    $('#hidden-other-subject').removeClass('hidden');
  } else {
    $('#subject-select').removeClass('col-xs-6')
      .addClass('col-xs-12');

    $('#hidden-other-subject').addClass('hidden');
  }
}
            
          
!
999px
Loading ..................

Console