Saludos,
Estoy haciendo un formulario y bueno ya lo que queria funciona... lo que no me hace es que cuando el formulariop esta totalmente vacio no me da ninguna advertencia, de igual manera envia el formulaio vacio....
esto es lo q estoy usando para validar campos..
Código PHP:
<script type="text/javascript">
var numero = 0;
// Funciones comunes
c= function (tag) { // Crea un elemento
return document.createElement(tag);
}
d = function (id) { // Retorna un elemento en base al id
return document.getElementById(id);
}
e = function (evt) { // Retorna el evento
return (!evt) ? event : evt;
}
f = function (evt) { // Retorna el objeto que genera el evento
return evt.srcElement ? evt.srcElement : evt.target;
}
addField = function () {
container = d('files');
span = c('SPAN');
span.className = 'file';
span.id = 'file' + (++numero);
field = c('INPUT');
field.name = 'archivos[]';
field.type = 'file';
a = c('A');
a.name = span.id;
a.href = '#';
a.onclick = removeField;
a.innerHTML = 'Quitar';
span.appendChild(field);
span.appendChild(a);
container.appendChild(span);
}
removeField = function (evt) {
lnk = f(e(evt));
span = d(lnk.name);
span.parentNode.removeChild(span);
}
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' Debe contener al menos una dirección de Email.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' Debe poseer un número.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' Campo Obligatorio.\n'; }
} if (errors) alert('Ha ocurrido lo siguiente:\n'+errors);
document.MM_returnValue = (errors == '');
} }
</script>
pero porque al darle enviar con todos los campos vacios sigue enviando>??? que debo hacer???
Gracias de antemano