validaciones

vdiaz2008
03 de Enero del 2009
Hola, quisiera saber como puedo hacer una validacion para que le campo nombre jams quede vacio y me de un alert, segun lo que vi en iternet puse esto, pero aun no resulta, muchas gracias desde ya!

<%@ page language="java" pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script type="text/javascript">
function valida_envia(){
//valido el nombre
if (document.agregarCliente.nc.value.length==0){
alert("Tiene que escribir su nombre")
document.agregarCliente.nc.focus()
return 0;
}
</script>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">

<title>Agregar Cliente</title>
</head>
<body>
<h1>
Agregar Cliente
</h1>
<h2>
Ingrese sus datos
</h2>
<html:form method="post">
<input type="hidden" value="true" name="iniciado" />
<table border="0">
<tr>
<td>
Nombre:
</td>
<td>
<html:text property="nombre" />
</td>
</tr>
<tr>
<td>
Direccion:
</td>
<td>
<html:text property="direccion" />
</td>
</tr>
<tr>
<td>
CUIT:
</td>
<td>
<html:text property="cuit" />
</td>
</tr>
<tr>
<td>
CBU:
</td>
<td>
<html:text property="cbu" />
</td>
</tr>
<tr>
<td>
Cuenta:
</td>
<td>
<html:select property="cuenta">
<option value="Elegir">
Elegir
<option value="ahorros">
Cta. Ahorros
<option value="corrinete">
Cta. Corriente
</html:select>
</td>
</tr>
<tr>
<td>
Categoría:
</td>
<td>
<html:select property="categoria">
<option value="Elegir">
Elegir
<option value="monotributista">
Monotributista
<option value="responsable inscripto">
Responsable Inscripto
</html:select>
</td>
</tr>
</tr>
</table>
<span style="font-weight: bold">Proveedor</span>
<br />

<label for="esproveedor">
Sí
</label>
<input type="radio" name="operacion" id="proveedor" value="si">
<label for="noesproveedor">
No
</label>
<input type="radio" name="operacion" id="proveedor" value="no">
<br />
<html:submit onclick="valida_envia()"/>
<html:cancel />
</html:form>
<a href="index.jsp">Volver a la pagina principal</a>
</body>