Foros del Web » Programando para Internet » Javascript »

Javascript que ejecuta otro javascript

Estas en el tema de Javascript que ejecuta otro javascript en el foro de Javascript en Foros del Web. buenas amigos de forosdelweb...necesito hacer lo siguiente: tengo un formulario en el cual valido que se llenen todos los campos y funciona muy bien....pero me ...
  #1 (permalink)  
Antiguo 29/12/2008, 15:03
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Javascript que ejecuta otro javascript

buenas amigos de forosdelweb...necesito hacer lo siguiente:
tengo un formulario en el cual valido que se llenen todos los campos y funciona muy bien....pero me gustaria que al terminar de comprobar que todos los campos estan con los datos validos se ejecute una segunda funcion llamada insertar()....
me explico :
al presionar el boton insertar llamo a la funcion validar () :

function validar(form)
{
var error = "POR FAVOR, ANTES DE ENVIAR EL FORMULARIO, DEBE COMPLETAR LOS SIGUIENTES CAMPOS:\n\n";
var a = ""

if (form.csr.value == "") { a += "CSR \n"; }
if (form.nombre_cliente.value == "") { a += "NOMBRE CLIENTE\n"; }
if (form.artefacto.value == "") { a += "ARTEFACTO\n"; }
if (form.serie.value == "") { a += "SERIE\n"; }
if (form.tipo_artefacto.selectedIndex==0) { a += "TIPO DE ARTEFACTO\n";}
if (form.csr.value.length<5) { a += "VALOR CSR INVALIDO \n"; }

if (a != "") { alert(error + a); return true; }
form.submit()
}

y la idea es que al final en vez de hacer el submit....me ejecute esta otra funcion :



function insertar()
{document.frmClientes.action='insert_clientes.asp? rut='+ document.frmClientes.rut.value+'&razon='+document. frmClientes.razon.value +'&folio='+document.frmClientes.folio.value +'&fecha='+document.frmClientes.fecha.value +'&orden='+ document.frmClientes.orden.value;
document.frmClientes.method="POST";
document.frmClientes.submit();
}


alguna idea de como hacer esto ???

De antemano muchas gracias
  #2 (permalink)  
Antiguo 29/12/2008, 18:10
Avatar de TresPuntoDos  
Fecha de Ingreso: septiembre-2008
Ubicación: Madrid, España
Mensajes: 242
Antigüedad: 15 años, 7 meses
Puntos: 3
Respuesta: Javascript que ejecuta otro javascript

En vez de poner form.submit() pon insertar()
__________________
Tres punto Dos - Mi Blog sobre J2EE, Java, Struts y Diseño Web
Proyecto BloJ - Crea tu blog Java
  #3 (permalink)  
Antiguo 29/12/2008, 18:54
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Javascript que ejecuta otro javascript

compadre....mi codigo completo es :

Código asp:
Ver original
  1. <%@ Language=VBScript %>
  2. <% Response.addHeader " ", "no-cache" %>
  3. <% Response.CacheControl = "Private" %>
  4. <% Response.Expires=0 %>
  5. <%
  6.  
  7. if Not IsEmpty(Request("rut")) then
  8.         rut = Request("rut")
  9.     end if
  10.     session("rut") =9999-9
  11.  
  12. set Cnn=Server.CreateObject("ADODB.Connection")
  13.     set rs=Server.CreateObject("ADODB.Recordset")
  14.     Cnn.Open Session("cnx")
  15.  
  16. strSQL = "select * from FACPVTA where rut='" &  rut & "' "
  17.          set rs = Cnn.Execute(strSQL)
  18.          cnn.Execute(strSQL)
  19.          
  20.          If Not rs.EOF then
  21.        
  22.         rut1   = rs.Fields("RUT")
  23.         session("rut") = rs.fields ("RUT")
  24.         razon  = rs.Fields("RAZON")
  25.         fecha_actual=date()
  26.         else
  27.        
  28. session("rut") =9999-9
  29.        
  30.        
  31.         end if
  32.      
  33.          
  34. %>
  35.  
  36.  
  37.  
  38.  
  39. <html>
  40. <meta http-equiv="Expires" content="0">
  41. <meta http-equiv="cache-control" content="no-store">
  42. <head>
  43. <title>Consulta de Facturas</title>
  44. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
  45. <!--
  46. body,td,th {
  47.     color: #FFFFFF;
  48. }
  49. body {
  50.     background-image: url(images/2.jpg);
  51. }
  52. -->
  53. </style></head>
  54. <body onLoad="document.frmClientes.rut.focus();" >
  55. <SCRIPT LANGUAGE="JAVASCRIPT">
  56.  
  57. function validar(form)
  58. {
  59. var error = "POR FAVOR, ANTES DE ENVIAR EL FORMULARIO, DEBE COMPLETAR LOS SIGUIENTES CAMPOS:\n\n";
  60. var a = ""
  61.  
  62.     if (form.rut.value == "") { a += "RUT \n"; }
  63.       if (form.razon.value == "") { a += "RAZON SOCIAL\n"; }
  64.     if (form.folio.value == "") { a += "FOLIO FACTURA\n"; }
  65.     if (form.orden.value == "") { a += "Nº PEDIDO\n"; }
  66.      
  67.  
  68.    
  69.    
  70.     if (a != "") { alert(error + a); return true; }
  71.  insertar()
  72. }
  73.  
  74.  
  75.  
  76.  
  77. function insertar()
  78.     {  
  79.    
  80.         document.frmClientes.action='insert_clientes.asp?rut='+ document.frmClientes.rut.value+'&razon='+document.frmClientes.razon.value +'&folio='+document.frmClientes.folio.value  +'&fecha='+document.frmClientes.fecha.value  +'&orden='+ document.frmClientes.orden.value;
  81.         document.frmClientes.method="POST";
  82.         document.frmClientes.submit();
  83.     }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.     </SCRIPT>
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. <form name="frmClientes" method="post" action="facturas_final.asp" autocomplete  = "off">
  100.   <table width="971" border="0" cellpadding="2" cellspacing="2">
  101.     <tr>
  102. <td width="120" height="32"> Rut </td>
  103. <%if session("rut") <>9999-9 then%>
  104. <td width="250"> Razon Social</td>
  105. <td width="120">Factura N°:</td>
  106. <td width="120">Fecha:</td>
  107. <td width="202"> N&deg; Pedido </td>
  108.  <%end if %>    
  109.        
  110. <tr>
  111. <td width="120" ><input name="rut" value="<%=rut%>"> </td>
  112. <%if session("rut") <>9999-9 then%>
  113. <td width="250"><input name="razon" value="<%=razon%>" size=50></td>
  114. <td width="120"><input name="folio" value="<%=folio%>" size=20 ></td>
  115. <td width="120"><input name="fecha" value="<%=fecha_actual%>" readonly size=20 ></td>
  116. <td width="202"><input name="orden" value="<%=orden%>" size=20></td>  
  117.     <%end if %>  
  118.    
  119.    
  120.    
  121.     <tr>
  122.      
  123.       <td colspan="2" align=left>
  124.         <p>
  125.            
  126.           <input name="submit" type="submit" value="Buscar">
  127.  
  128. </td>
  129.    
  130.  
  131. <%if session("rut") <>9999-9 then%>
  132.      <td colspan="2" align=left>
  133.    
  134.  <input type="button" value="Terminar" onClick="validar(this.form)">
  135.    
  136.     </td>
  137.     <%end if %>
  138.      </tr>
  139.   </table>
  140. </FORM>
  141. </body>
  142. </html>

y me dice error de "el objeto no acepta esta propiedad o metodo"...linea 49
y esa es la de:

body {
background-image: url(images/2.jpg);
}

o sea extraño el error.....que podra ser ??
  #4 (permalink)  
Antiguo 30/12/2008, 03:33
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Javascript que ejecuta otro javascript

En realidad no se refiere a esa línea 49, sino a la línea 49 del código generado en el navegador. Así que dale en el navegador a "Ver código fuente" y busca la línea 49.

Como indicación general, yo que tú pondría al <form> y a los <input> a cada uno su id:
Código html:
Ver original
  1. <form name="frmClientes" id="frmClientes" method="post" action="facturas_final.asp" autocomplete  = "off">
  2. <!-- ... -->
  3. <td width="120" ><input name="rut" id="rut" value="<%=rut%>"> </td>
  4. <%if session("rut") <>9999-9 then%>
  5. <td width="250"><input name="razon" id="razon" value="<%=razon%>" size=50></td>
  6. <td width="120"><input name="folio" id="folio" value="<%=folio%>" size=20 ></td>
  7. <td width="120"><input name="fecha" id="fecha" value="<%=fecha_actual%>" readonly size=20 ></td>
  8. <td width="202"><input name="orden" id="orden" value="<%=orden%>" size=20></td>  
  9. <!-- ... -->

Y luego haría referencia a ellos en Javascript usando document.getElementById:

Código javascript:
Ver original
  1. function insertar() {
  2.     var formulario = document.getElementById("frmClientes");
  3.     formulario.action='insert_clientes.asp?rut=' + document.getElementById("rut").value +
  4.                        '&razon=' + document.getElementById("razon").value +
  5.                        '&folio=' + document.getElementById("folio").value +
  6.                        '&fecha=' + document.getElementById("fecha").value +
  7.                        '&orden=' + document.getElementById("orden").value;
  8.     formulario.method="POST";
  9.     formulario.submit();
  10. }
  #5 (permalink)  
Antiguo 30/12/2008, 09:35
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Javascript que ejecuta otro javascript

compadre...gracias por tu respuesta....pero hice todos los cambios que mencionas en tu post (venkman) y nada...sigue mandando el mismo error ahora en la linea 51...que viendo en el navegador es la linea de formulario.submit....
que podra ser ??
  #6 (permalink)  
Antiguo 31/12/2008, 13:51
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Javascript que ejecuta otro javascript

¿Podrías pegar:

1- El código completo que se ve al dar a "Ver código fuente"
2- Exactamente el mensaje de error que te da con la línea y la descripción exacta

por favor?
  #7 (permalink)  
Antiguo 02/01/2009, 10:03
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Javascript que ejecuta otro javascript

compadre....aca esta el codigo :


Código asp:
Ver original
  1. <html>
  2. <meta http-equiv="Expires" content="0">
  3. <meta http-equiv="cache-control" content="no-store">
  4. <head>
  5. <title>Consulta de Facturas</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
  7. <!--
  8. body,td,th {
  9.     color: #FFFFFF;
  10. }
  11. body {
  12.     background-image: url(images/2.jpg);
  13. }
  14. -->
  15. </style></head>
  16. <body onLoad="document.frmClientes.rut.focus();" >
  17. <SCRIPT LANGUAGE="JAVASCRIPT">
  18.  
  19. function validar(form)
  20. {
  21. var error = "POR FAVOR, ANTES DE ENVIAR EL FORMULARIO, DEBE COMPLETAR LOS SIGUIENTES CAMPOS:\n\n";
  22. var a = ""
  23.  
  24.     if (form.rut.value == "") { a += "RUT \n"; }
  25.       if (form.razon.value == "") { a += "RAZON SOCIAL\n"; }
  26.     if (form.folio.value == "") { a += "FOLIO FACTURA\n"; }
  27.     if (form.orden.value == "") { a += "Nº PEDIDO\n"; }
  28.      
  29.  
  30.    
  31.    
  32.     if (a != "") { alert(error + a); return true; }
  33.  insertar()
  34. }
  35.  
  36.  
  37.  
  38.  
  39. function insertar()
  40.     {  
  41.    
  42.         document.frmClientes.action='insert_clientes.asp?rut='+ document.frmClientes.rut.value+'&razon='+document.frmClientes.razon.value +'&folio='+document.frmClientes.folio.value  +'&fecha='+document.frmClientes.fecha.value  +'&orden='+ document.frmClientes.orden.value;
  43.         document.frmClientes.method="POST";
  44.         document.frmClientes.submit();
  45.     }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     </SCRIPT>
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. <form name="frmClientes" method="post" action="2.asp" autocomplete  = "off">
  62.   <table width="971" border="0" cellpadding="2" cellspacing="2">
  63.     <tr>
  64. <td width="120" height="32"> Rut </td>
  65.  
  66. <td width="250"> Razon Social</td>
  67. <td width="120">Factura N°:</td>
  68. <td width="120">Fecha:</td>
  69. <td width="202"> N° Pedido </td>
  70.      
  71.        
  72. <tr>
  73. <td width="120" ><input name="rut" value="15792248-3"> </td>
  74.  
  75. <td width="250"><input name="razon" value="Dark Mcloud Inc." size=50></td>
  76. <td width="120"><input name="folio" value="" size=20 ></td>
  77. <td width="120"><input name="fecha" value="02-01-2009" readonly size=20 ></td>
  78. <td width="202"><input name="orden" value="" size=20></td>  
  79.        
  80.    
  81.    
  82.    
  83.     <tr>
  84.      
  85.       <td colspan="2" align=left>
  86.         <p>
  87.            
  88.           <input name="submit" type="submit" value="Buscar">
  89.  
  90. </td>
  91.    
  92.  
  93.  
  94.      <td colspan="2" align=left>
  95.    
  96.  <input type="button" value="Terminar" onClick="validar(this.form)">
  97.    
  98.     </td>
  99.    
  100.      </tr>
  101.   </table>
  102. </FORM>
  103. </body>
  104. </html>

el error es :

Linea: 49
Caracter: 9
Error: El Objeto no acepta esta propiedad o metodo
Codigo: 0
Direccion URL : http://localhost/inventario/2.asp...

de antemano muchas gracias
  #8 (permalink)  
Antiguo 03/01/2009, 05:12
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Javascript que ejecuta otro javascript

No veo que hayas hecho los cambios que te dije que hicieras y que tú decías que habías hecho.
  #9 (permalink)  
Antiguo 05/01/2009, 12:07
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Javascript que ejecuta otro javascript

Código asp:
Ver original
  1. <html>
  2. <meta http-equiv="Expires" content="0">
  3. <meta http-equiv="cache-control" content="no-store">
  4. <head><title>Consulta de Facturas</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
  6. <!--
  7. body,td,th {
  8.     color: #FFFFFF;
  9. }
  10. body {
  11.     background-image: url(images/2.jpg);
  12. }
  13. -->
  14. </style></head>
  15. <body onLoad="document.frmClientes.rut.focus();" >
  16. <SCRIPT LANGUAGE="JAVASCRIPT">
  17.  
  18. function validar(form)
  19. {
  20. var error = "POR FAVOR, ANTES DE ENVIAR EL FORMULARIO, DEBE COMPLETAR LOS SIGUIENTES CAMPOS:\n\n";
  21. var a = ""
  22.  
  23.     if (form.rut.value == "") { a += "RUT \n"; }
  24.       if (form.razon.value == "") { a += "RAZON SOCIAL\n"; }
  25.     if (form.folio.value == "") { a += "FOLIO FACTURA\n"; }
  26.     if (form.orden.value == "") { a += "Nº PEDIDO\n"; }
  27.      
  28.  
  29.    
  30.    
  31.     if (a != "") { alert(error + a); return true; }
  32.  insertar()
  33. }
  34.  
  35.  
  36.       function insertar() {
  37.  
  38.           var formulario = document.getElementById("frmClientes");
  39.  
  40.           formulario.action='insert_clientes.asp?rut=' + document.getElementById("rut").value +
  41.                              '&razon=' + document.getElementById("razon").value +
  42.  
  43.                              '&folio=' + document.getElementById("folio").value +
  44.  
  45.                              '&fecha=' + document.getElementById("fecha").value +
  46.                    '&orden=' + document.getElementById("orden").value;
  47.  
  48.           formulario.method="POST";
  49.  
  50.           formulario.submit();
  51.  
  52.       }
  53.  
  54.  
  55.  
  56.     </SCRIPT>
  57.  
  58.  
  59.  
  60.  
  61.       <form name="frmClientes" id="frmClientes" method="post" action="facturas_final.asp" autocomplete  = "off">
  62.  
  63.  
  64.       <td width="120" ><input name="rut" id="rut" value="<%=rut%>"> </td>
  65.  
  66.       <%if session("rut") <>9999-9 then%>
  67.  
  68.       <td width="250"><input name="razon" id="razon" value="<%=razon%>" size=50></td>
  69.  
  70.       <td width="120"><input name="folio" id="folio" value="<%=folio%>" size=20 ></td>
  71.  
  72.       <td width="120"><input name="fecha" id="fecha" value="<%=fecha_actual%>" readonly size=20 ></td>
  73.  
  74.       <td width="202"><input name="orden" id="orden" value="<%=orden%>" size=20></td>  
  75.  
  76.  
  77.    
  78.    
  79.     <tr>
  80.      
  81.       <td colspan="2" align=left>
  82.         <p>
  83.            
  84.           <input name="submit" type="submit" value="Buscar">
  85.  
  86. </td>
  87.    
  88.  
  89.  
  90.      <td colspan="2" align=left>
  91.    
  92.  <input type="button" value="Terminar" onClick="validar(this.form)">
  93.    
  94.     </td>
  95.    
  96.      </tr>
  97.   </table>
  98. </FORM>
  99. </body>
  100. </html>

perdon compadre...me habia equivocado en postear el codigo...pero lo hice como dijiste tu..(lo que pasa es que tenia 2 paginas que se llamaban casi =....
el error al parecer lo da cuando tendria que ejecutarse el insertar()...porque al menos comprueba bien que esten todos los campos con datos...

el error lo da en la linea 40...donde esta:
formulario.submit();
de antemano muchas gracias

Última edición por darkmcloud; 05/01/2009 a las 12:25
  #10 (permalink)  
Antiguo 05/01/2009, 12:32
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Javascript que ejecuta otro javascript

Ah... ya veo el problema.

Esto: <input name="submit" type="submit" value="Buscar">

NO le pongas nunca de nombre submit a un elemento de un formulario, porque entonces se confunde el "submit función del formulario" con el "submit elemento del formulario" y no funciona.

Ponle otro nombre a eso.
  #11 (permalink)  
Antiguo 05/01/2009, 12:52
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Javascript que ejecuta otro javascript

tenias toda la razon compadre....jejejeje..
lo siento por las molestias causadas....le borre el nombre y el formulario valida los datos y los envia...te pasaste por la ayuda
Muchas Gracias y hasta pronto
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 22:04.