cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-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.

            
              <html>
  <head>
    <title>HTML5 Manejo del Atributo 'required' usando JQuery</title>
  </head>  
  <body>
    <div class="cform">
      <form actio="#">
   <input type="text" name="field1" placeholder="Nombre (*)" required/> 
   <input type="email" name="field2" placeholder="Email (*)" required/>
   <input type="tel" name="field2" placeholder="Telefono" />
   <input type="submit" value="Enviar" />
      </form>  
      <span class="requeridof">(*) Campo requerido</span>
    </div> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  </body>    
 </html>  
            
          
!
            
              .cform{
    font: 95% Arial, Helvetica, sans-serif;
    max-width: 400px;
    margin: 10px auto;
    padding:30px  16px;
    background: #a3ccff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 5px solid #0056c1;
    
}

.form-error {
	display:none;
	position:absolute;
	top:0;
	right:0;
	font-size:11px;
	line-height:20px;
	font-style:italic;
	background:#9A2C2C;
	color:#FFF;
	padding:5px 10px;
	box-shadow:inset 0 -1px 3px rgba(0,0,0,0.3),inset 0 1px 3px rgba(0,0,0,0.3);
	-webkit-box-shadow:inset 0 -1px 3px rgba(0,0,0,0.3),inset 0 1px 3px rgba(0,0,0,0.3);
	-moz-box-shadow:inset 0 -1px 3px rgba(0,0,0,0.3),inset 0 1px 3px rgba(0,0,0,0.3);
}


.cform input[type="tel"],
.cform input[type="text"],
.cform input[type="date"],
.cform input[type="datetime"],
.cform input[type="email"],
.cform input[type="number"],
.cform input[type="search"],
.cform input[type="time"],
.cform input[type="url"],
.cform textarea,
.cform select 
{
    -webkit-transition: all 0.30s ease-in-out;
    -moz-transition: all 0.30s ease-in-out;
    -ms-transition: all 0.30s ease-in-out;
    -o-transition: all 0.30s ease-in-out;
    outline: none;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    width: 100%;
    background: #fff;
    margin-bottom: 4%;
    border: 1px solid #ccc;
    padding: 3%;
    color: #555;
    font: 95% Arial, Helvetica, sans-serif;
}
.cform input[type="tel"]:focus,
.cform input[type="text"]:focus,
.cform input[type="date"]:focus,
.cform input[type="datetime"]:focus,
.cform input[type="email"]:focus,
.cform input[type="number"]:focus,
.cform input[type="search"]:focus,
.cform input[type="time"]:focus,
.cform input[type="url"]:focus,
.cform textarea:focus,
.cform select:focus
{
    box-shadow: 0 0 5px #43D1AF;
    padding: 3%;
    border: 1px solid #43D1AF;
}

.requeridof {
  margin-top:10px;
  text-align:center;
  display:block;
  font: italic bold 12px/30px Georgia, serif;
  color:red;
}

.cform input[type="submit"], 
.cform input[type="button"]{
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    width: 100%;
    padding: 3%;
    background: #0049a4;
    border-bottom: 2px solid #30C29E;
    border-top-style: none;
    border-right-style: none;
    border-left-style: none;    
    color: #fff;
}
.cform input[type="submit"]:hover,
.cform input[type="button"]:hover{
    background: #025dcd;
}

            
          
!
            
              // Demo script, feature detect inverted
$(function () {
			
			// feature detect
			var supportsRequired = 'required' in document.createElement('input');
			
			// loop through required attributes
			$('[required]').each(function () {
			
				// if 'required' isn't supported
				if (!supportsRequired) {
				
					// this
					var self = $(this);
				
					// swap attribute for class
					self.removeAttr('required').addClass('required');
					
					// append an error message
					self.parent().append('<span class="form-error">Requerido</span>');
					
				}
				
			});
			
			// submit the form
			$('.form').on('submit', function (e) {
			
				// loop through class name required
				$('.required').each(function () {
				
					// this
					var self = $(this);
					
					// check shorthand if statement for input[type] detection
					var checked = (self.is(':checkbox') || self.is(':radio')) 
					? self.is(':not(:checked)') && $('input[name=' + self.attr('name') + ']:checked').length === 0 
					: false;
					
					// run the empty/not:checked test
					if (self.val() === '' || checked) {
							
						// show error if the values are empty still (or re-emptied)
						// this will fire after it's already been checked once
						self.siblings('.form-error').show();
						
						// stop form submitting
						e.preventDefault();
					
					// if it's passed the check
					} else {
					
						// hide the error
						self.siblings('.form-error').hide();
						
					}
					
				});
				
				// all other form submit handlers here
			
			});
			
			// key change on all form inputs
			$('input, textarea', '.form').on('blur change', function () {
			
				// this
				var self = $(this);
					
				// check shorthand if statement for input[type] detection
				var checked = (self.is(':checkbox') || self.is(':radio')) 
				? self.is(':not(:checked)') && $('input[name=' + self.attr('name') + ']:checked').length === 0 
				: false;
				
				// if empty on change, i.e. if data is removed
				if (self.val() === '' || checked) {
				
					// show/keep the error in view
					self.siblings('.form-error').show();
				
				// if there's a value or checked
				} else {
				
					// hide the error
					self.siblings('.form-error').hide();
					
				}
				
			});
		
		});

            
          
!
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