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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console