나는이 양식이 있습니다JS 양식이 submited되어 정의되지 않은 오류가
<form onsubmit="return validarIDC()">
<div class="labelBox">
<div>
<label>Destinatario:</label>
<select name="destinatario">
<option value="hombre">Sr.</option>
<option value="mujer">Sra.</option>
</select>
</div>
<div>
<label>Apellido y<br>nombre:</label>
<input type="text" id="nombre"> *
</div>
<div id="ubicarCampo">
<label>Razón Social:</label>
<input type="text" name="razon">
</div>
<div>
<label>Email:</label>
<input type="email" name="email"> *
</div>
<div>
<label>Teléfono:</label>
<input type="text" name="telefono"> *
</div>
<div>
<label>Celular:</label>
<input type="text" name="celular">
</div>
<div>
<label>Via de Contacto:</label>
<select name="via">
<option value="opc1">E-mail</option>
<option value="opc2">Telefono</option>
<option value="opc3">Correo postal</option>
</select>
</div>
<div>
<label>Comentarios:</label>
<textarea max="300"></textarea>
</div>
<input name="submit" type="submit" value="Enviar">
</div>
</form>
<script type="text/javascript" src="script.js"></script>
을하고 내가 입력에서 모든 데이터의 유효성을 검사하는 기능을 수행했습니다, 그리고 더 자세한 사항 후, 하나의 오류에 대한 exept 완벽하게 작동 나는 그것이 경고 (MSG)하지만 놀랍게도 모든 조건이 내가 오류의 측면에 잘 접착 "정의되지 않은"사실 수의 .. 콘솔 팝 제출 그래서
function validarIDC() {
var errores = [];
var er = /^[\w]+$/;
if (document.contactForm.nombre.value == "" || document.contactForm.nombre.value == null) {
errores.push("El nombre es obligatorio.");
}
else if (!er.test(document.contactForm.nombre.value)) {
errores.push("El nombre contiene caracteres no validos o Espacios.");
}
if (document.contactForm.telefono.value == "") {
errores.push("Debe ingresar un telefono")
}
else if (isNaN(document.contactForm.telefono.value)) {
errores.push("El campo telefono contiene caracteres no validos.");
}
if (document.contactForm.email.value == "") {
errores.push("Debe especificar una dirección de Email.");
}
if (document.contactForm.celular.value !== "" && isNaN(document.contactForm.celular.value)) {
errores.push("El campo celular contiene caracteres no validos.");
}
if (errores.length > 0) {
msg = alert("Error/es: \n");
for (var i = 0; i < errores.length; i++) {
msg += errores[i] + "\n";
}
alert(msg);
return false;
}
document.contactForm.submit.disable = true;
alert("Los datos han sido enviados exitosamente!");
return true;
}
: 코드, 여기에 JS입니다 로그가 아무 말도 안하고 내가 뭘 잘못하고 있는지 모르겠어. 제발 .. 누구든지 이걸 도와 줘?
참고로, 텍스트 상자의 값은 null이 아니므로 이러한 검사는 쓸모가 없습니다. – epascarello