CodePen

HTML

            
              # Email Domain Datalist Helper

Shows a list of suggestions after you've hit the @.

<label for="email">Email</label>
<input id="email" name="email" type="email" placeholder="your@email.com">
            
          
!

CSS

            
              @import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro);

body {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: large;
  max-width: 500px;
  margin: 0 auto;
}
input[type=email] {
  font-size: large;
  width: 400px;
}
label {
  display: block;
  font-size: small;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #999;
}
            
          
!
? ?
? ?
Must be a valid URL.
+ add another resource
via CSS Lint

JS

            
              var EmailDomainSuggester = {
  
  domains: ["yahoo.com", "gmail.com", "google.com", "hotmail.com", "me.com", "aol.com", "mac.com", "live.com", "comcast.com", "googlemail.com", "msn.com", "hotmail.co.uk", "yahoo.co.uk", "facebook.com", "verizon.net", "att.net", "gmz.com", "mail.com"],
  
  bindTo: $('#email'),
  
  init: function() {
    this.addElements();
    this.bindEvents();
  },
  
  addElements: function() {
    // Create empty datalist
    this.datalist = $("<datalist />", {
      id: 'email-options'
    }).insertAfter(this.bindTo);
    // Corelate to input
    this.bindTo.attr("list", "email-options");
  },
  
  bindEvents: function() {
    this.bindTo.on("keyup", this.testValue);
  },
    
  testValue: function(event) {
    var el = $(this),
        value = el.val();
                    
    // email has @
    // remove != -1 to open earlier
    if (value.indexOf("@") != -1) {
      value = value.split("@")[0];
      EmailDomainSuggester.addDatalist(value); 
    } else {
      // empty list
      EmailDomainSuggester.datalist.empty();
    }
     
  },
  
  addDatalist: function(value) {
    var i, newOptionsString = "";
    for (i = 0; i < this.domains.length; i++) {
      newOptionsString += 
        "<option value='" + 
          value + 
          "@" +
          this.domains[i] +
        "'>";
    }
    
    // add new ones
    this.datalist.html(newOptionsString);
  }
  
}

EmailDomainSuggester.init();
            
          
!
Must be a valid URL.
+ add another resource
via JS Hint
Loading ..................