Ver Mensaje Individual
  #6 (permalink)  
Antiguo 09/10/2009, 00:04
infinitum88
 
Fecha de Ingreso: octubre-2009
Mensajes: 40
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: :::document write:::

Hola este es el codigo que tengo hasta ahorita:
Cita:
<script type="text/javascript">
validateform=function()
{
var txtnombre = new array(document.getelementbyid('txtnombre'), document.frmcontactanos['txtnombre'].value);
var txtdireccion = new array(document.getelementbyid('txtdireccion'), document.frmcontactanos['txtdireccion'].value);
var txtemail = new array(document.getelementbyid('txtemail'), document.frmcontactanos['txtemail'].value);
var txttelefono = new array(document.getelementbyid('txttelefono'), document.frmcontactanos['txttelefono'].value);
var txtpoblacion = new array(document.getelementbyid('txtpoblacion'), document.frmcontactanos['txtpoblacion'].value);
var txtasunto = new array(document.getelementbyid('txtasunto'), document.frmcontactanos['txtasunto'].value);
var txtcomentario = new array(document.getelementbyid('txtcomentario'), document.frmcontactanos['txtcomentario'].value);
var submit = document.getelementbyid('btnenviar');

/* eventos */
txtnombre[0].onfocus = onfocus; txtnombre[0].onblur = onblur;
txtdireccion[0].onfocus = onfocus; txtdireccion[0].onblur = onblur;
txtemail[0].onfocus = onfocus; txtemail[0].onblur = onblur;
txttelefono[0].onfocus = onfocus; txttelefono[0].onblur = onblur;
txtpoblacion[0].onfocus = onfocus; txtpoblacion[0].onblur = onblur;
txtasunto[0].onfocus = onfocus; txtasunto[0].onblur = onblur;
txtcomentario[0].onfocus = onfocus; txtcomentario[0].onblur = onblur;
submit.onclick = validatefields;

/* funciones */
function onfocus() { if(document.frmcontactanos[this.name].value==eval(this.name)[1]) document.frmcontactanos[this.name].value='' }

function onblur() {
var value = document.frmcontactanos[this.name].value;
value = value.replace(/^\s*/, ''); value = value.replace(/\s*$/, '');
if(!value) document.frmcontactanos[this.name].value = eval(this.name)[1]
}

function validatefields() {
if(document.frmcontactanos['txtnombre'].value == txtnombre[1]) { document.frmcontactanos['txtnombre'].focus(); document.write("el campo 'nombre' es obligatorio."); }
else if(document.frmcontactanos['txtdireccion'].value == txtdireccion[1]) { document.frmcontactanos['txtdireccion'].focus(); document.write('el campo "dirección" es obligatorio.'); }
else if(document.frmcontactanos['txtemail'].value == txtemail[1]) { document.frmcontactanos['txtemail'].focus(); document.write('el campo "email" es obligatorio.'); }
else if(document.frmcontactanos['txttelefono'].value == txttelefono[1]) { document.frmcontactanos['txttelefono'].focus(); document.write('el campo "teléfono" es obligatorio.'); }
else if(document.frmcontactanos['txtpoblacion'].value == txtpoblacion[1]) { document.frmcontactanos['txtpoblacion'].focus(); document.write('el campo "población" es obligatorio.'); }
else if(document.frmcontactanos['txtasunto'].value == txtasunto[1]) { document.frmcontactanos['txtasunto'].focus(); document.write('el campo "asunto" es obligatorio.'); }
else if(document.frmcontactanos['txtcomentario'].value == txtcomentario[1]) { document.frmcontactanos['txtcomentario'].focus(); document.write('el campo "comentario" es obligatorio.'); }
else { return true; }
return false;
}
}

if(document.all&&window.attachevent) { window.attachevent("onload",validateform); } // ie-win
else if(window.addeventlistener) { window.addeventlistener("load",validateform,false) ; }

function solo_numerico(variable)
{
numer=parseint(variable);
if (isnan(numer))
{
return "";
}
return numer;
}
function valnumero(control)
{
control.value=solo_numerico(control.value);
}

claseerror="requerido";

function validoemail(email)
{
var s = email;
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(s))
return true;
else
return false;
}

function valida_envia()
{
var txtnombre = document.frmcontactanos.txtnombre.value;
var txtdireccion = document.frmcontactanos.txtdireccion.value;
var txttelefono = document.frmcontactanos.txttelefono.value;
var txtemail = document.frmcontactanos.txtemail.value;
var txtpoblacion = document.frmcontactanos.txtpoblacion.value;
var txtasunto = document.frmcontactanos.txtasunto.value;
var txtcomentario = document.frmcontactanos.txtcomentario.value;

if (txtnombre.length==0 || txtdireccion.length==0 || txttelefono.length==0 || txtemail.length==0 || txtpoblacion.length==0 || txtasunto.length==0 || txtcomentario.length==0)
{
document.getelementbyid("error").style.display="bl ock";
if (txtnombre.length==0) document.frmcontactanos.txtnombre.classname=clasee rror; else document.frmcontactanos.txtnombre.classname="";
if (txtdireccion.length==0) document.frmcontactanos.txtdireccion.classname=cla seerror; else document.frmcontactanos.txtdireccion.classname="";
if (txttelefono.length==0) document.frmcontactanos.txttelefono.classname=clas eerror; else document.frmcontactanos.txttelefono.classname="";
if (txtemail.length==0) document.frmcontactanos.txtemail.classname=claseer ror; else document.frmcontactanos.txtemail.classname="";
if (txtpoblacion.length==0) document.frmcontactanos.txtpoblacion.classname=cla seerror; else document.frmcontactanos.txtpoblacion.classname="";
if (txtasunto.length==0) document.frmcontactanos.txtasunto.classname=clasee rror; else document.frmcontactanos.txtasunto.classname="";
if (txtcomentario.length==0) document.frmcontactanos.txtcomentario.classname=cl aseerror; else document.frmcontactanos.txtcomentario.classname="" ;
return 0;
}
else
{
document.frmcontactanos.submit();
}

}

function revalida(cual)
{
var ese = document.getelementbyid(cual).value;
if (ese.length>0){document.getelementbyid(cual).class name="";}

var txtnombre = document.frmcontactanos.txtnombre.value;
var txtdireccion = document.frmcontactanos.txtdireccion.value;
var txttelefono = document.frmcontactanos.txttelefono.value;
var txtemail = document.frmcontactanos.txtemail.value;
var txtpoblacion = document.frmcontactanos.txtpoblacion.value;
var txtasunto = document.frmcontactanos.txtasunto.value;
var txtcomentario = document.frmcontactanos.txtcomentario.value;

if (txtnombre.length>0 && txtdireccion.length>0 && txttelefono.length>0 && txtemail.length>0 && txtpoblacion.length>0&& txtasunto.length>0 && txtcomentario.length>0){document.getelementbyid("e rror").style.display="none";}
if (txtemail.length>0){
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
{
document.frmcontactanos.txtemail.classname="";
document.getelementbyid("error2").style.display="n one";
}
else
{
document.getelementbyid("error2").style.display="b lock";
document.frmcontactanos.txtemail.classname=claseer ror;
}
}
}
</script>
y en mis input text tengo lo siguiente:

Cita:
<input name="txtnombre" type="text" id="txtnombre" tabindex="1" class="input-text" title="introduce tu nombre" value="---nombre---" accesskey="n" onkeypress="javascript:revalida(this.id);">
<p id="error" class='error' style='display:none'>introduce el nombre es obligatorio</p>