Foros del Web » Programando para Internet » Javascript »

Ingresa igual los Datos

Estas en el tema de Ingresa igual los Datos en el foro de Javascript en Foros del Web. Hola tengo un boton el cual valida si han sido ingresados 2 datos en particular de un formulario lo que pasa es que si falta ...
  #1 (permalink)  
Antiguo 16/04/2009, 14:54
Avatar de TonyChile  
Fecha de Ingreso: marzo-2009
Ubicación: Maipú, Santiago
Mensajes: 422
Antigüedad: 15 años, 1 mes
Puntos: 7
Pregunta Ingresa igual los Datos

Hola tengo un boton el cual valida si han sido ingresados 2 datos en particular de un formulario lo que pasa es que si falta uno de ellos debe salir un mensaje diciendo que falta un dato y no debe grabar. Me muestra el mensaje pero al darle clic al boton aceptar del mensaje me inserta igual el dato no importando si estan ambos datos ingresados y asi no me sirve. . Al tener los dos datos a consultar y otros datos extras si los graba bien

Lo otro como puedo hacer para que me valide que el text1 q equivale en la base al NUM_CHIP sii esta repetido me arroje un mensaje de clave repetida y no permita grabar

les adjunto el codigo

Esto es para el tipo de dato permitido en cada text

Código asp:
Ver original
  1. <script language="javascript">
  2. <!--
  3. function LP0_data(){
  4.    telefono=true
  5.     //si no tiene 8 caracteres no es válido
  6.    if (document.Form1.text7.value.length != 8){
  7.          telefono=false
  8.       else{
  9.          for (i=0;i>=8;i++){
  10.             fono = document.Form1.text7.value.charAt(i)
  11.             if (LP_data(fono)==""){
  12.                telefono=false
  13.                break;
  14.             }
  15.             }
  16.          }
  17.       }
  18.    return CPValido
  19. }
  20. -->
  21. </script>
  22.  
  23. <script language="javascript">
  24. <!--
  25. function LP1_data(){
  26. var key=window.event.keyCode;  
  27. if ((key < 65 || key > 90) && (key < 97 || key > 122) && key != 32){
  28. window.event.keyCode=0;
  29. }}
  30. -->
  31. </script>
  32.  
  33. <script language="javascript">
  34. <!--
  35. function LP2_data(){
  36. var key=window.event.keyCode;  
  37. if ((key < 65 || key > 90) && (key < 97 || key > 122)  && (key < 48 || key > 57) && key != 32){
  38. window.event.keyCode=0;
  39. }}
  40. -->
  41. </script>
  42.  
  43.  
  44. <script language=JavaScript>
  45. function no() {
  46.    var myForm = document.Form1;
  47.    if (myForm.text1.value == "" || myForm.text7.value == "") {
  48.       alert("Los campos Número de Chip y Número de Teléfono son obligatorios");
  49.       if (myForm.text7.value == "") {
  50.          myForm.text7.focus();
  51.       }
  52.       else {
  53.          myForm.text1.focus();
  54.       }
  55.    }
  56.    else {
  57.       alert("El Celular Número  " + myForm.text7.value + "  a sido ingresado");
  58.    }
  59. }
  60.  
  61. </script>

Y este es el Form

Código asp:
Ver original
  1. <%
  2. dim valor
  3. valor = Request.QueryString("valor")
  4. if num_chip = "" then
  5. %>
  6.  
  7. <form name="Form1" method="Post" action="agregachip.asp?valor=1">
  8.  
  9.  <table width="308" border="2" align="center" cellpadding="1" cellspacing="0" name="tabla">
  10.   <tr><td colspan=2 align="center" class="Estilo5">Agregar Nuevo CHIP</td>
  11.   </tr>
  12.   <tr><td colspan="2" height=5></td></tr>
  13.      
  14.    <tr>
  15.       <td width="38%" nowrap class="Estilo7">N&uacute;mero de Chip:</td>
  16.       <td colspan="2">
  17.           <input type="text" name ="text1" size="25" maxlength="20"  onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Los datos deben ser númericos y no estar en blanco');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>  
  18.       </td>                
  19.    </tr>
  20.  
  21.    <tr>
  22.       <td  width="38%" nowrap class="Estilo7">Dato1:</td>
  23.       <td colspan="2">
  24.           <input type="text" name="text2" size="25" maxlength="12" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Los ');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  25.       </td>
  26.    </tr>
  27.    
  28.    <tr>
  29.       <td width="38%" nowrap class="Estilo7">Dato2:</td>
  30.       <td colspan="2">
  31.           <input type="text" name="text3" size="25" maxlength="5" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Los mmmm');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  32.       </td>
  33.    </tr>  
  34.    
  35.   <tr>
  36.       <td width="38%" nowrap class="Estilo7">Serie De Carpeta:</td>
  37.       <td colspan="2">
  38.           <input name="text4" size="25" maxlength="13" onKeypress="LP2_data()" onMouseover="showtip2(this,event,'Ingrese el Número de Serie');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  39.       </td>
  40.   </tr>      
  41.  
  42.   <tr>
  43.       <td width="38%" nowrap class="Estilo7">Pin:</td>
  44.       <td colspan="2">
  45.           <input type="text" name="text5" size="25" maxlength="4" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Ingrese el Pin del Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  46.       </td>
  47.   </tr>
  48.            
  49.   <tr>
  50.       <td width="38%" nowrap class="Estilo7">Puk:</td>
  51.       <td colspan="2">
  52.            <input type="text" name="text6" size="25" maxlength="8" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Ingrese el Puk del Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  53.       </td>
  54.   </tr>
  55.  
  56.   <tr>
  57.       <td width="38%" nowrap class="Estilo7">N&uacute;mero de Tel&eacute;fono:</td>
  58.       <td colspan="2">
  59.            <input type="text" name="text7" size="25"  maxlength="12" onKeyPress="LP_data()"onblur="LP0_data()" onMouseover="showtip2(this,event,'Ingrese el Número de Teléfono asociado al Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  60.       </td>
  61.   </tr>
  62.  
  63.   <tr>
  64.       <td width="38%" nowrap class="Estilo7">Fecha Entrega Chip:</td>
  65.       <td colspan="2">
  66.            <input name="text8" size="25" maxlength="10" onKeypress="if(event.keyCode == 13) event.returnValue = false;" onChange="valFecha(document.Form1.text8)"  onMouseover="showtip2(this,event,'Ingrese la Fecha con formato dd/mm/aaaa. Ejemplo (01-01-2009 o 01/01/2009)');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  67.       </td>
  68.   </tr>
  69.    
  70.   <tr>
  71.       <td width="38%" nowrap class="Estilo7">Fecha Retiro Chip:</td>
  72.       <td colspan="2">
  73.            <input name="text9" size="25" maxlength="10" onKeypress="if(event.keyCode == 13) event.returnValue = false;" onChange="valFecha(document.Form1.text9)"  onMouseover="showtip2(this,event,'Ingrese la Fecha con formato dd/mm/aaaa. Ejemplo (01-01-2009 o 01/01/2009)');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  74.       </td>
  75.   </tr>
  76.  
  77.   <tr>
  78.       <td width="38%" nowrap class="Estilo7">Asignado:</td>
  79.       <td colspan="2">
  80.            <input name="text10" size="25" maxlength="50" onKeypress="LP1_data()" onMouseover="showtip2(this,event,'Ingrese el El nombre de la persona asociada al Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  81.       </td>  
  82.   </tr>
  83.  
  84.   <tr>
  85.       <td width="38%" nowrap class="Estilo7">No Asignado:</td>
  86.       <td colspan="2">
  87.            <input type="text" name="text11" size="25" maxlength="50" onKeypress="LP1_data()" onMouseover="showtip2(this,event,'Ingrese el nombre de la persona a quien se retiro el chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  88.       </td>
  89.   </tr>
  90.            
  91.   <tr>
  92.       <td width="38%" nowrap class="Estilo7">Notas:</td>
  93.       <td colspan="2">
  94.            <input name="text12" size="25" maxlength="200" onKeypress="LP1_data()" onMouseover="showtip2(this,event,'Permite ingresar datos extras que no se encuentran en las otras opciones');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  95.       </td>
  96.   </tr>
  97.  
  98.   <tr>
  99.       <td colspan="6" align="center">
  100.           <input name="agregar" type="submit" id="agregar" onClick="no()" value="&nbsp;&nbsp;Agregar&nbsp;&nbsp;" onMouseover="showtip2(this,event,'Pulse el Botón para agregar los datos ingresados');" onMouseout="hidetip2();" STYLE="cursor: hand">      
  101.       </td>
  102.       <td width="13%"></td>
  103.   </tr>
  104.  </table>
  105. <%
  106. end if
  107. %>
  108. <%
  109. if valor = 1 then
  110.   num_chip = request.Form("text1")
  111.   dato1 = request.Form("text2")
  112.   dato2 = request.Form("text3")
  113.   serie_carpeta = request.Form("text4")
  114.   pin = request.Form("text5")
  115.   puk = request.Form("text6")
  116.   movil = request.Form("text7")
  117.   fecha_entrega_chip = request.Form("text8")
  118.   fecha_retiro_chip = request.Form("text9")
  119.   asignado = request.Form("text10")
  120.   no_asignado = request.Form("text11")
  121.   notas = request.Form("text12")
  122.  
  123.  
  124.   SQL = "INSERT INTO CHIP (NUM_CHIP, DATO1, DATO2, SERIE_CARPETA, PIN, PUK, MOVIL, FECHA_ENTREGA_CHIP, FECHA_RETIRO_CHIP, ASIGNADO, NO_ASIGNADO, NOTAS) VALUES " &  "('" & num_chip & "', '" & dato1 & "', '" & dato2 & "', '" & serie_carpeta & "', '" & pin & "', '" & puk & "', '" & movil & "', '" & fecha_entrega_chip & "', '" & fecha_retiro_chip & "', '" & asignado & "', '" & no_asignado & "', '" & notas & "')"
  125.  
  126.  
  127.   set obj_conn=server.createobject("ADODB.connection")
  128.       obj_conn.open "PRUEBA"
  129.       obj_conn.execute SQL
  130.       obj_conn.Close
  131.       set obj_conn = Nothing
  132.  
  133.  
  134. end if
  135. %>
  136. </form>

Necesito ayuda urgente en esto y ya no se me ocurre como hacerlo aunq creo que debe ser una cosa poca pero no la puedo pillar
  #2 (permalink)  
Antiguo 16/04/2009, 15:18
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Ingresa igual los Datos

En lugar de usar el evento onclick del input, usa el evento onsubmit del formulario.
Código javascript:
Ver original
  1. return no();
Y, dentro de la función, cuando no valide, usa:
Código javascript:
Ver original
  1. return false;
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 17/04/2009, 09:20
Avatar de TonyChile  
Fecha de Ingreso: marzo-2009
Ubicación: Maipú, Santiago
Mensajes: 422
Antigüedad: 15 años, 1 mes
Puntos: 7
Respuesta: Ingresa igual los Datos

David el grande si que lo eres gracias por tu respuesta ahora me funciona a la perfeccion

Ahora abusando de tu buena disposicion te quiero hacer otra pregunta.

Mira tengo que actualizar unos datos la idea es que cuando se ingrese el numero de telefono (text19) se pueda validar si este se encuentra o no en la base de datos sql server 2000. Si esta que carge todos los datos existentes en los text que sigen para asi modificar solo los que son necesarios y no tener que ingresar todos los datos nuevamente que es como lo esta haciendo hasta ahora.

Adjunto el codigo para que los campos no esten en blanco:

Código asp:
Ver original
  1. <script language=JavaScript>
  2. function no() {
  3.    var myForm = document.Formc;
  4.    if (myForm.text13.value == "" || myForm.text19.value == "") {
  5.       alert("Los campos Número de Teléfono y Número de Chip son obligatorios");
  6.       return false;
  7.       if (myForm.text19.value == "") {
  8.          myForm.text19.focus();
  9.       }
  10.       else {
  11.          myForm.text19.focus();
  12.      
  13.       }
  14.    }
  15.    else {
  16.       alert("El Celular Número  " + myForm.text19.value + "  a sido ingresado");
  17.    }
  18. }
  19.  
  20. </script>


Y este es el codigo del form

Código asp:
Ver original
  1. <%
  2. If num_chip0 = "" then
  3. %>
  4.  
  5. <form name="Formc" method="Post" onSubmit="return no();" action="actualizachip.asp">
  6.  
  7. <table width="308" border="2" align="center" cellpadding="1" cellspacing="0" name="tabla1">
  8.  
  9.   <tr><td colspan=2 align="center" class="Estilo5">Ingrese los Nuevos Datos de Chip</td>
  10.   </tr>
  11.   <tr><td colspan="2" height=5></td></tr>
  12.  
  13.   <tr>
  14.       <td width="38%" nowrap class="Estilo7">N&uacute;mero de Tel&eacute;fono:</td>
  15.       <td colspan="2">
  16.           <input name="text19" size="25" maxlength="12" onKeyPress="LP3_data()"onblur="LP0_data()" onMouseover="showtip2(this,event,'Ingrese el Número de Teléfono asociado al Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  17.       </td>
  18.   </tr>
  19.      
  20.   <tr>
  21.       <td width="38%" nowrap class="Estilo7">N&uacute;mero de Chip:</td>
  22.       <td colspan="2">
  23.           <input name ="text13" size="25" maxlength="20" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Ingrese el Número de Chip. Este campo no debe estar vacio');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  24.       </td>
  25.   </tr>
  26.    
  27.   <tr>
  28.       <td width="38%" nowrap class="Estilo7">Dato1:</td>
  29.       <td colspan="2">
  30.           <input name="text14"  size="25" maxlength="12" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Ingrese Dato1');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  31.       </td>
  32.   </tr>      
  33.  
  34.   <tr>
  35.       <td width="38%" nowrap class="Estilo7">Dato2:</td>
  36.       <td colspan="2">
  37.           <input name="text15" size="25" maxlength="5" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Ingrese Dato2');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  38.       </td>  
  39.   </tr>
  40.  
  41.   <tr>
  42.       <td width="38%" nowrap class="Estilo7">Serie de Carpeta:</td>
  43.       <td colspan="2">
  44.           <input name="text16" size="25" maxlength="13" onKeypress="LP2_data()" onMouseover="showtip2(this,event,'Ingrese el Número de Serie');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  45.       </td>
  46.   </tr>
  47.          
  48.   <tr>
  49.       <td width="38%" nowrap class="Estilo7">Pin:</td>
  50.       <td colspan="2">
  51.           <input name="text17" size="25" maxlength="4" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Ingrese el Pin del Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>      
  52.       </td>
  53.   </tr>
  54.          
  55.   <tr>
  56.       <td width="38%" nowrap class="Estilo7">Puk:</td>
  57.       <td colspan="2">
  58.           <input name="text18" size="25" maxlength="8" onKeyPress="LP_data()" onMouseover="showtip2(this,event,'Ingrese el Puk del Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  59.       </td>
  60.   </tr>
  61.  
  62.   <tr>
  63.      <td width="38%" nowrap class="Estilo7">Fecha Entrega Chip:</td>
  64.      <td colspan="2">
  65.           <input name="text20" size="25" maxlength="10" onKeypress="if(event.keyCode == 13) event.returnValue = false;" onChange="valFecha(document.Formc.text20)"  onMouseover="showtip2(this,event,'Ingrese la Fecha con formato dd/mm/aaaa. Ejemplo (01-01-2009 o 01/01/2009)');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  66.      </td>
  67.   </tr>
  68.        
  69.   <tr>
  70.      <td width="38%" nowrap class="Estilo7">Fecha Retiro Chip:</td>
  71.      <td colspan="2">
  72.           <input name="text21" size="25" maxlength="10" onKeypress="if(event.keyCode == 13) event.returnValue = false;" onChange="valFecha(document.Formc.text21)"  onMouseover="showtip2(this,event,'Ingrese la Fecha con formato dd/mm/aaaa. Ejemplo (01-01-2009 o 01/01/2009)');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  73.      </td>
  74.   </tr>        
  75.  
  76.   <tr>
  77.      <td width="38%" nowrap class="Estilo7">Asignado:</td>
  78.      <td colspan="2">
  79.           <input name="text22" size="25" maxlength="50" onKeypress="LP1_data()" onMouseover="showtip2(this,event,'Ingrese el El nombre de la persona asociada al Chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  80.      </td>
  81.   </tr>
  82.          
  83.   <tr>
  84.      <td width="38%" nowrap class="Estilo7">No Asignado:</td>
  85.      <td colspan="2">
  86.           <input name="text23" size="25" maxlength="50" onKeypress="LP1_data()" onMouseover="showtip2(this,event,'Ingrese el nombre de la persona a quien se retiro el chip');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  87.      </td>
  88.   </tr>
  89.          
  90.   <tr>
  91.      <td width="38%" nowrap class="Estilo7">Notas:</td>
  92.      <td colspan="2">
  93.           <input name="text24" size="25" maxlength="200" onKeypress="LP1_data()" onMouseover="showtip2(this,event,'Permite ingresar datos extras que no se encuentran en las otras opciones');" onMouseout="hidetip2();" STYLE="cursor: hand"><BR>    
  94.      </td>
  95.   </tr>
  96.            
  97.   <tr>
  98.      <td colspan="6" align="center">
  99.          <input type="Submit" value="Actualizar" onMouseover="showtip2(this,event,'Pulse el Botón para poder grabar los nuevos datos del usuario');" onMouseout="hidetip2();" STYLE="cursor: hand">
  100.      </td>
  101.      <td width="13%"></td>
  102.   </tr>      
  103. </table>
  104. <%
  105.   num_chip0 = request.Form("text13")
  106.   dato1_0 = request.Form("text14")
  107.   dato2_0 = request.Form("text15")
  108.   serie_carpeta0 = request.Form("text16")
  109.   pin0 = request.Form("text17")
  110.   puk0 = request.Form("text18")
  111.   movil0 = request.Form("text19")
  112.   fecha_entrega_chip0 = request.Form("text20")
  113.   fecha_retiro_chip0 = request.Form("text21")
  114.   asignado0 = request.Form("text22")
  115.   no_asignado0 = request.Form("text23")
  116.   notas0 = request.Form("text24")
  117.  
  118.    SQL1_0 = "UPDATE CHIP SET  NUM_CHIP = '" & num_chip0 & "', DATO1 = '" & dato1_0 & "', DATO2 = '" & dato2_0 & "', SERIE_CARPETA = '" & serie_carpeta0 & "', PIN = '" & pin0 & "', PUK = '" & puk0 & "', FECHA_ENTREGA_CHIP = '" & fecha_entrega_chip0 & "', FECHA_RETIRO_CHIP = '" & fecha_retiro_chip0 & "', ASIGNADO = '" & asignado0 & "', NO_ASIGNADO = '" & no_asignado0 & "', NOTAS = '" & notas0 & "' WHERE MOVIL = '" & movil0 & "'"
  119.  
  120.   set obj_conn0 = server.createobject ("ADODB.Connection")
  121.   obj_conn0.Open "PRUEBA"
  122.   obj_conn0.Execute sql1_0
  123.   obj_conn0.Close
  124.   set obj_conn0 = Nothing
  125.  
  126. %>
  127. </form>
  128. <%
  129. end if
  130. %>

De ante mano muchas gracias a todos
  #4 (permalink)  
Antiguo 17/04/2009, 09:51
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Ingresa igual los Datos

Para eso debes usar AJAX, para consultar al servidor si ese dato ya existe.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 17/04/2009, 10:12
Avatar de TonyChile  
Fecha de Ingreso: marzo-2009
Ubicación: Maipú, Santiago
Mensajes: 422
Antigüedad: 15 años, 1 mes
Puntos: 7
Respuesta: Ingresa igual los Datos

Mmmmmmmmmmm gracias david nuevamente
Ahora tengo un problema no se nada de ajax

y no seria posible haciendo nose
un if donde se consulte si text19 =MOVIL(nombre en base de datos)
y si son = carge todos los datos asociado a ese MOVIL dentro de los otros text


  #6 (permalink)  
Antiguo 17/04/2009, 10:29
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Ingresa igual los Datos

Pero desde Javascript no puedes consultar la base de datos, necesariamente tienes que hacer una petición al servidor (usando AJAX). Puedes empezar a documentarte aquí:
http://www.forosdelweb.com/f77/faqs-...o-ajax-332366/
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #7 (permalink)  
Antiguo 17/04/2009, 10:59
Avatar de TonyChile  
Fecha de Ingreso: marzo-2009
Ubicación: Maipú, Santiago
Mensajes: 422
Antigüedad: 15 años, 1 mes
Puntos: 7
Respuesta: Ingresa igual los Datos

Gracias voy a ver de que van las FAQs de ajax
Y lo publico aca sino puedo
Ya tengo una idea en mente por sino me funciona lo de ajax
voy a hacerlo de otra forma
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:32.