zerokilled no consigo que me funcione.
Si mi caja de texto es "nombre", como tendría que hacerlo?
Os pongo el formulario con una caja de texto de ejemplo:
Código:
<html>
<head>
<script type="text/javascript">
<!--
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+='- El '+nm+' debe de ser válido.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\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 += '- El campo '+nm+' es obligatorio.\n'; }
} if (errors) alert('Ha ocurrido el siguiente error: \n\n'+errors);
document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>
<body>
<form action="tratar-enviar-contactar.aspx" method="post">
<table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="82" height="21">(*) Nombre:</td>
<td width="182" height="30"><input type="text" name="nombre" id="nombre" /></td>
</tr>
<tr>
<td align="center"><input name="button" type="submit" id="button" onclick="MM_validateForm('nombre');return document.MM_returnValue" value="Enviar" /></td>
</tr>
</table>
</form>
</body>
</html>