Foros del Web » Programando para Internet » Javascript »

Llamada de una funcion desde otra

Estas en el tema de Llamada de una funcion desde otra en el foro de Javascript en Foros del Web. Estimados: Necesito llamar una funcion desde otra en javascript y todo lo que he encontrado no me ha funcionado....este es el codigo de la primera ...
  #1 (permalink)  
Antiguo 20/08/2008, 14:23
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 10 meses
Puntos: 0
Pregunta Llamada de una funcion desde otra

Estimados:

Necesito llamar una funcion desde otra en javascript y todo lo que he encontrado no me ha funcionado....este es el codigo de la primera funcion desde donde quiero llamar a la otra....

Cita:
function Validar(form)
{
if (form.nombre.value == "")
{ alert("Por favor ingrese su nombre"); form.nombre.focus(); return; }

if (form.rut.value == "")
{ alert("Por favor ingrese su Rut");
form.rut.focus();
return; }

if (form.email.value == "")
{ alert("Por favor ingrese su dirección de e-mail"); form.email.focus(); return; }


if (form.telefono.value == "")
{ alert("Por favor ingrese su número de teléfono"); form.telefono.focus(); return; }

if (form.ciudad.value == "")
{ alert("Por favor ingrese Ciudad"); form.ciudad.focus(); return; }

if (form.cantidad.selectedIndex==0){
alert("Debe seleccionar cantidad de entradas.")
form.cantidad.focus()
return 0;
}
if (form.ubicacion.selectedIndex==0){
alert("Debe seleccionar ubicación de la(s) entrada(s).")
form.ubicacion.focus()
return 0;
}
if (form.edad.value == "")
{ alert("Por favor ingrese edad"); form.edad.focus(); return; }

if (form.email.value.indexOf('@', 0) == -1 ||
form.email.value.indexOf('.', 0) == -1)
{ alert("Dirección de e-mail inválida"); form.email.focus(); return; }

form.submit();
}
y estos son los parametros que estoy utilizando para hacer la llamada...

Cita:
Rut(document.form.rut.value);
y este es el codigo de la otra funcion....

Cita:
<script>
function revisarDigito( dvr )
{
dv = dvr + ""
if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k' && dv != 'K')
{
alert("Debe ingresar un digito verificador valido");
window.document.form.rut.focus();
window.document.form.rut.select();
return false;
}
return true;
}

function revisarDigito2( crut )
{
largo = crut.length;
if ( largo < 2 )
{
alert("Debe ingresar el rut completo")
window.document.form.rut.focus();
window.document.form.rut.select();
return false;
}
if ( largo > 2 )
rut = crut.substring(0, largo - 1);
else
rut = crut.charAt(0);
dv = crut.charAt(largo-1);
revisarDigito( dv );

if ( rut == null || dv == null )
return 0

var dvr = '0'
suma = 0
mul = 2

for (i= rut.length -1 ; i >= 0; i--)
{
suma = suma + rut.charAt(i) * mul
if (mul == 7)
mul = 2
else
mul++
}
res = suma % 11
if (res==1)
dvr = 'k'
else if (res==0)
dvr = '0'
else
{
dvi = 11-res
dvr = dvi + ""
}
if ( dvr != dv.toLowerCase() )
{
alert("EL rut es incorrecto")
window.document.form.rut.focus();
window.document.form.rut.select();
return false
}

return true
}

function Rut(texto)
{
var tmpstr = "";
for ( i=0; i < texto.length ; i++ )
if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
tmpstr = tmpstr + texto.charAt(i);
texto = tmpstr;
largo = texto.length;

if ( largo < 2 )
{
alert("Debe ingresar el rut completo")
window.document.form.rut.focus();
window.document.form.rut.select();
return false;
}

for (i=0; i < largo ; i++ )
{
if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
{
alert("El valor ingresado no corresponde a un R.U.T valido");
window.document.form.rut.focus();
window.document.form.rut.select();
return false;
}
}

var invertido = "";
for ( i=(largo-1),j=0; i>=0; i--,j++ )
invertido = invertido + texto.charAt(i);
var dtexto = "";
dtexto = dtexto + invertido.charAt(0);
dtexto = dtexto + '-';
cnt = 0;

for ( i=1,j=2; i<largo; i++,j++ )
{
//alert("i=[" + i + "] j=[" + j +"]" );
if ( cnt == 3 )
{
dtexto = dtexto + '.';
j++;
dtexto = dtexto + invertido.charAt(i);
cnt = 1;
}
else
{
dtexto = dtexto + invertido.charAt(i);
cnt++;
}
}

invertido = "";
for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )
invertido = invertido + dtexto.charAt(i);

window.document.form.rut.value = invertido.toUpperCase()

if ( revisarDigito2(texto) )
return true;

return false;
}
</script>

Se entiende? espero que si y que me puedan orientar....he estado todo el dia dando la hora...

De antemano muchisimas gracias a todos!!!

Saludos

Karla
  #2 (permalink)  
Antiguo 20/08/2008, 14:28
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años, 1 mes
Puntos: 839
Pregunta Respuesta: Llamada de una funcion desde otra

No entendí, ¿te da algún error? ¿dónde estás haciendo la llamada?.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 20/08/2008, 14:42
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Llamada de una funcion desde otra

quiero que verifique primero si el campo esta vacio...si no es asi...que llame a la otra funcion....a rut....

Cita:
if (form.rut.value == "")
{ alert("Por favor ingrese su Rut");
form.rut.focus();
return; }

else
Rut(document.form.rut.value);

  #4 (permalink)  
Antiguo 20/08/2008, 14:44
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años, 1 mes
Puntos: 839
Pregunta Respuesta: Llamada de una funcion desde otra

¿Y qué sucede cuando haces la llamada? ¿Marca algún error?
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 20/08/2008, 15:02
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Llamada de una funcion desde otra

Nop...nada....pero queda ahi....no pasa al siguiente if...
  #6 (permalink)  
Antiguo 20/08/2008, 15:06
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años, 1 mes
Puntos: 839
Exclamación Respuesta: Llamada de una funcion desde otra

¿Podrías poner tu formulario para que haga las pruebas?. Porque si no ejecuta el código posterior lo más probable es que la función tenga algún error.

Otra cosa, ¿no deberías tomar el valor de retorno de Rut?
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #7 (permalink)  
Antiguo 20/08/2008, 15:10
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Llamada de una funcion desde otra

mi formulario....

Cita:
<form METHOD="post" ACTION="reserva.asp">
<p><img src="image/00.jpg" width="622" height="420"></p>
<img src="image/line01.gif" width="626" height="2"><BR><BR>



<div align="center"><center> <table width="509" border="0" cellspacing="2" cellpadding="5" align="center">

<tr>
<td width="118"><font face="Monotype Corsiva" size="3">Nombre (*)</font></td>
<td width="170"> <input type="text" name="nombre"></td>

<td rowspan="4" width="183" valign="top">
<table width="28" border="0" cellspacing="2" cellpadding="5">
<tr>
<td><img src="image/00RED.JPG" width="69" height="51"></td>
<td><img src="image/00BL.JPG" width="69" height="51"></td>
</tr>
<tr>
<td>&nbsp; </td>
<td><img src="image/00YL.JPG" width="69" height="51"></td>
</tr>

</table>
</td>
</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3">Rut (*) </font></td>
<td width="170"> <input type="text" name="rut">
</td>
</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3"> E-mail (*)</font></td>
<td width="170"><input type="text" name="email">
</td>
</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3"> Telefono (*)</font></td>
<td width="170"> <input type="text" name="telefono">
</td>

</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3"> Ciudad (*)</font></td>
<td width="170"><input type="text" name="ciudad">
</td>
</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3"> Cantidad (*)</font></td>

<td width="170"> <SELECT name="cantidad"><OPTION>
</OPTION>

<OPTION value=1>1 ENTRADA</OPTION>
<OPTION value=2>2 ENTRADAS</OPTION>
<OPTION value=3>3 ENTRADAS</OPTION>
<OPTION value=4>4 ENTRADAS</OPTION>
<OPTION value=5>5 ENTRADAS</OPTION>
<OPTION value=6>+ DE 5 ENTRADAS</OPTION>
</SELECT>
</td>
</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3"> Ubicación (*)</font></td>

<td width="170"> <SELECT name="ubicacion"><OPTION>
</OPTION>

<OPTION value="Vipgolden">VIP GOLDEN - $80.000</OPTION>
<OPTION value="Vippreferncial">VIP PREFERENCIAL - $50.000</OPTION>
<OPTION value="Preferencial">PLATEA - $30.000</OPTION>
<OPTION value="Preferencial">TRIBUNA - $15.000</OPTION>
</SELECT>
</td>
</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3"> Edad (*)</font></td>
<td><input type="text" name="edad" size="5" maxlength="2"></td>
</tr>
<tr>
<td width="118"><font face="Monotype Corsiva" size="3">Comentarios</font></td>
<td colspan="2">
<textarea name="comentarios" cols="45" rows="4"></textarea>
</td>

</tr>

<table width="509" border="0" align="center" cellpadding="5" cellspacing="2" dwcopytype="CopyTableCell">
<tr>
<td colspan="3">
<div align="center">
<p>
<input TYPE="button" VALUE="Enviar" onClick="Validar(this.form)">
<input type="reset" name="reset" value="Limpiar">
</p>

</div>
</td>
</tr>
</table>

</table>
</center></div>

</table>

</form>
  #8 (permalink)  
Antiguo 20/08/2008, 15:31
Avatar de Fernand0  
Fecha de Ingreso: septiembre-2005
Ubicación: Buenos Aires
Mensajes: 610
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: Llamada de una funcion desde otra

Cita:
Iniciado por kvera Ver Mensaje
Nop...nada....pero queda ahi....no pasa al siguiente if...
no se mucho sobre funcionamiento... pero el RETURN terminaria con la funcion... vendria a ser como un BREAK en un WHILE..
  #9 (permalink)  
Antiguo 20/08/2008, 15:33
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años, 1 mes
Puntos: 839
Exclamación Respuesta: Llamada de una funcion desde otra

Exactamente como pensé, el código tiene varios errores, por ejemplo, estás poniendo:
Código PHP:
window.document.form.rut 
En muchas partes del código, lo cual es un error, lo que puedes hacer es pasarle también como parámetro a la función Rut el form y manejarlo así:
Código PHP:
form.rut 
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #10 (permalink)  
Antiguo 20/08/2008, 15:40
 
Fecha de Ingreso: julio-2008
Mensajes: 39
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Llamada de una funcion desde otra

a ver...vamos a probar...
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:44.