cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Untitled

A Pen By Captain Anonymous

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.

            
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<form onsubmit="return validar();" id="formValidar" method="post">

<input type="text" name="campo1" placeholder="Campo 1...">
<br><br>
<input type="text" name="campo2" placeholder="Campo 2...">
<br><br>
<textarea name="campo3" placeholder="Campo 3..."></textarea>
<br><br>
<div id="res"></div>
<input type="submit" value="Enviar">

</form>
            
          
!
            
              function validar(){
	
	//Serializamos todos los campos del form dinámicamente
	var campos= $('#formValidar').serializeArray();
	//Por defecto la validación es 1
	var validar=1;
	
	//Recorremos todos los campos del formulario
	$.each(campos, function(index, value) {
		//Si uno de los valores esta vacio pasamos la validación a 0
		if(value.value=='') validar=0;
	});

	//Si la validación es 0 no enviamos el form y mostramos un mensaje
	if(validar==0){
		$('#res').text('Completa todos los campos');
	     return false;	
	} else {
	//Si la validación es 1  enviamos el form
		$('#res').text('Enviando...');
		return true;
		
	}



}
            
          
!
999px
Loading ..................

Console