Foros del Web » Programando para Internet » Javascript »

Condiciones y validaciones

Estas en el tema de Condiciones y validaciones en el foro de Javascript en Foros del Web. Hola, quiero hacer esto: Código PHP: function  NuevoAviso (){           var  APARATO  =  document . forms [ 'form1' ]. elements [ 'APARATO' ];      if ( APARATO ...
  #1 (permalink)  
Antiguo 06/12/2012, 06:24
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Condiciones y validaciones

Hola, quiero hacer esto:

Código PHP:
function NuevoAviso(){
    
     var 
APARATO document.forms['form1'].elements['APARATO'];

     if (
APARATO.value.length == 0){ 

       
alert("¡Insertar el Aparato!");

         
APARATO.focus();

     }else{ 
     
     if (
confirm("¿Nuevo aviso?")){
         
     
document.form1.submit()    
    
     }else{ 
                   
                } 
Esta bien? no me funciona.

Gracias y un saludo
  #2 (permalink)  
Antiguo 06/12/2012, 07:44
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Condiciones y validaciones

lo que no está bien es el foro donde lo colocaste, eso es javascript.

además la línea:

document.form1.submit();

¿no se supone que estás usando las colecciones?:

document.forms['form1'].submit();

te faltan algunos punto y coma al final (;) y veo que faltan llaves de cierre ¿o copiaste solo un pedazo?

reportado para que sea movido al foro de JS
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #3 (permalink)  
Antiguo 06/12/2012, 07:51
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: Condiciones y validaciones

Tema movido desde PHP a Javascript
__________________
http://es.phptherightway.com/
thats us riders :)
  #4 (permalink)  
Antiguo 06/12/2012, 08:28
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Condiciones y validaciones

Maycol, tendré en cuenta tus sugerencias siempre me enseñan mucho.
Muchísimas gracias a los dos.
Saludos

Última edición por satjaen; 06/12/2012 a las 08:58
  #5 (permalink)  
Antiguo 06/12/2012, 13:10
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Condiciones y validaciones

Cita:
Iniciado por maycolalvarez Ver Mensaje
lo que no está bien es el foro donde lo colocaste, eso es javascript.

además la línea:

document.form1.submit();

¿no se supone que estás usando las colecciones?:

document.forms['form1'].submit();

te faltan algunos punto y coma al final (;) y veo que faltan llaves de cierre ¿o copiaste solo un pedazo?

reportado para que sea movido al foro de JS
Maycol, lo he puesto así:

Código PHP:
function NuevoAviso(){
    
     var 
APARATO document.forms['form1'].elements['APARATO'];

     if (
APARATO.value.length == 0){ 

     
alert("¡Insertar el Aparato!");

       
APARATO.focus();

     }else{ 
     
      if (
confirm("¿Nuevo aviso?"))
                { 
                   
alert("¡Enviado!");
                   
document.forms['form1'].submit();    
                } 
                else 
                { 
                  
alert("¡Cancelado!");
                  
window.location.href "menu3.php?id="+NUM_USUARIO;
    
                } 
        }
     

Pero tengo dos problemas:

1º- Cuando hago ¡Enviado!document.forms['form1'].submit(); me manda el form1 que es un insert pero despues no lleva a menu8.php:

Código PHP:
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());
  
$insertGoTo "menu8.php?id=" $_POST["NUM_USUARIO"];
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));


2º- Cuando hago ¡Cancelado!window.location.href = "menu3.php?id="+NUM_USUARIO; no lleva a menu3.php


Gracias y un saludo.
  #6 (permalink)  
Antiguo 06/12/2012, 13:52
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Condiciones y validaciones

veo que desde HTML/JS haces uso de una variable NUM_USUARIO que no sé de donde proviene ni de dónde se define, además de que la pasas por GET y en PHP intentas recuperarla por POST ¿¿¿¿ ????
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #7 (permalink)  
Antiguo 06/12/2012, 14:05
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Condiciones y validaciones

Cita:
Iniciado por maycolalvarez Ver Mensaje
veo que desde HTML/JS haces uso de una variable NUM_USUARIO que no sé de donde proviene ni de dónde se define, además de que la pasas por GET y en PHP intentas recuperarla por POST ¿¿¿¿ ????
Gracias Maycol por contestar. Claro es que estoy liado. La variable NUM_USUARIO es una variable que tengo en el formulario y la mando a menu8.php donde la recojo por GET:
Código PHP:
$NUM_USUARIO=$_GET['id'];
mysql_select_db($database_conexion$conexion);
$query_Recordset1 "SELECT * FROM usuarios where NUM_USUARIO like '$NUM_USUARIO'";
$Recordset1 mysql_query($query_Recordset1$conexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1); 
  #8 (permalink)  
Antiguo 06/12/2012, 14:22
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Condiciones y validaciones

sí, pero el punto es que ésa variable NO existe en JS, y la estás usando

toma aire, respira profundo y trata de resolver ese enredo que tienes, porque la semántica te esta fallando mucho:

$NUM_USUARIO=$_GET['id']; //id es id ¿¿y NUM_USUARIO de donde en el cliente??
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #9 (permalink)  
Antiguo 06/12/2012, 14:33
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Condiciones y validaciones

Cita:
Iniciado por maycolalvarez Ver Mensaje
sí, pero el punto es que ésa variable NO existe en JS, y la estás usando

toma aire, respira profundo y trata de resolver ese enredo que tienes, porque la semántica te esta fallando mucho:

$NUM_USUARIO=$_GET['id']; //id es id ¿¿y NUM_USUARIO de donde en el cliente??
La variable, la tengo en el formulario donde hago el insert:

Código PHP:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO avisos (NUM_USUARIO, NUM_APARATO, NUM_DIRECCION, SERIE, FECHA_RECEPCION, OPERADOR, TECNICO, CODIGO_SINTOMA, SINTOMA, PROPORCIONADO, FECHA_EMISION, HORA_INICIO, HORA_FIN, ESTADO, RECLAMACION, URGENTE, PRESUPUESTO, TIENE_PRESUPUESTO, MARCA, BOLETIN, MODELO, APARATO, FACTURADO, TIPO_INTERVENCION, FECHA_FACTURACION, NUM_BOLETIN, SITUACION, COD_AVERIA, AVERIA, SERIE_FACTURA, NUM_FACTURAU, NUM_ALBARANU, NUM_FACTURAF, NUM_ALBARANF, NUM_FACTURAA, NUM_ALBARANA, IMPORTE, GARANTIA, MINUTOS, USUARIO, FABRICANTE, ASEGURADORA, ZONA, ID_RECEPCION, ID_INTERVENCION, FECHA_REALIZACION, HORA_ENTRADA, HORA_SALIDA, OBS_GENERALES, OBS_PRIVADAS, DISTRIBUIDOR) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['NUM_USUARIO'], "int"),
                       
GetSQLValueString($_POST['NUM_APARATO'], "int"),
                       
GetSQLValueString($_POST['NUM_DIRECCION'], "int"),
                       
GetSQLValueString($_POST['SERIE'], "text"),
                       
GetSQLValueString($_POST['FECHA_RECEPCION'], "date"),
                       
GetSQLValueString($_POST['OPERADOR'], "text"),
                       
GetSQLValueString($_POST['TECNICO'], "text"),
                       
GetSQLValueString($_POST['CODIGO_SINTOMA'], "text"),
                       
GetSQLValueString($_POST['SINTOMA'], "text"),
                       
GetSQLValueString($_POST['PROPORCIONADO'], "text"),
                       
GetSQLValueString($_POST['FECHA_EMISION'], "date"),
                       
GetSQLValueString($_POST['HORA_INICIO'], "text"),
                       
GetSQLValueString($_POST['HORA_FIN'], "text"),
                       
GetSQLValueString($_POST['ESTADO'], "int"),
                       
GetSQLValueString($_POST['RECLAMACION'], "text"),
                       
GetSQLValueString($_POST['URGENTE'], "text"),
                       
GetSQLValueString($_POST['PRESUPUESTO'], "text"),
                       
GetSQLValueString($_POST['TIENE_PRESUPUESTO'], "text"),
                       
GetSQLValueString($_POST['MARCA'], "text"),
                       
GetSQLValueString($_POST['BOLETIN'], "text"),
                       
GetSQLValueString($_POST['MODELO'], "text"),
                       
GetSQLValueString($_POST['APARATO'], "text"),
                       
GetSQLValueString($_POST['FACTURADO'], "text"),
                       
GetSQLValueString($_POST['TIPO_INTERVENCION'], "text"),
                       
GetSQLValueString($_POST['FECHA_FACTURACION'], "date"),
                       
GetSQLValueString($_POST['NUM_BOLETIN'], "text"),
                       
GetSQLValueString($_POST['SITUACION'], "text"),
                       
GetSQLValueString($_POST['COD_AVERIA'], "text"),
                       
GetSQLValueString($_POST['AVERIA'], "text"),
                       
GetSQLValueString($_POST['SERIE_FACTURA'], "text"),
                       
GetSQLValueString($_POST['NUM_FACTURAU'], "int"),
                       
GetSQLValueString($_POST['NUM_ALBARANU'], "int"),
                       
GetSQLValueString($_POST['NUM_FACTURAF'], "int"),
                       
GetSQLValueString($_POST['NUM_ALBARANF'], "int"),
                       
GetSQLValueString($_POST['NUM_FACTURAA'], "int"),
                       
GetSQLValueString($_POST['NUM_ALBARANA'], "int"),
                       
GetSQLValueString($_POST['IMPORTE'], "double"),
                       
GetSQLValueString($_POST['GARANTIA'], "text"),
                       
GetSQLValueString($_POST['MINUTOS'], "int"),
                       
GetSQLValueString($_POST['USUARIO'], "text"),
                       
GetSQLValueString($_POST['FABRICANTE'], "text"),
                       
GetSQLValueString($_POST['ASEGURADORA'], "text"),
                       
GetSQLValueString($_POST['ZONA'], "text"),
                       
GetSQLValueString($_POST['ID_RECEPCION'], "int"),
                       
GetSQLValueString($_POST['ID_INTERVENCION'], "int"),
                       
GetSQLValueString($_POST['FECHA_REALIZACION'], "date"),
                       
GetSQLValueString($_POST['HORA_ENTRADA'], "text"),
                       
GetSQLValueString($_POST['HORA_SALIDA'], "text"),
                       
GetSQLValueString($_POST['OBS_GENERALES'], "text"),
                       
GetSQLValueString($_POST['OBS_PRIVADAS'], "text"),
                       
GetSQLValueString($_POST['DISTRIBUIDOR'], "text"));

  
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());
  
$idmysql_insert_id();
  
$insertGoTo "menu8.php?id=".$NUM_USUARIO;    
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));

Código PHP:
mysql_select_db($database_conexion$conexion);
$query_Recordset1 "SELECT * FROM usuarios where NUM_USUARIO like '$NUM_USUARIO'";
$Recordset1 mysql_query($query_Recordset1$conexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1); 
Código PHP:
<th scope="col"><?php echo $row_Recordset1['NUM_USUARIO']; ?></th>

Y Maycol, para mandar el formulario aqui:

Código PHP:
Ver original
  1. if (confirm("¿Nuevo aviso?"))
  2.                 {  
  3.                    alert("¡Enviado!");
  4.                    document.forms['form1'].submit();
  5.                   }

No hace falta que este la variable NUM_USUARIO no?

De todas formas el js lo he dejado así:

Código Javascript:
Ver original
  1. function NuevoAviso(){
  2.    
  3.      var APARATO = document.forms['form1'].elements['APARATO'];
  4.      var NUM_USUARIO = document.forms['form1'].elements['NUM_USUARIO'];
  5.  
  6.      if (APARATO.value.length == 0){
  7.  
  8.      alert("¡Insertar el Aparato!");
  9.  
  10.         APARATO.focus();
  11.  
  12.      }else{
  13.      
  14.       if (confirm("¿Nuevo aviso?"))
  15.                 {
  16.                    alert("¡Enviado!");
  17.                    document.forms['form1'].submit();   
  18.                 }
  19.                 else
  20.                 {
  21.                   alert("¡Cancelado!");
  22.                   window.location.href = "menu3.php?id="+NUM_USUARIO;
  23.    
  24.                 }
  25.         }
  26.      
  27. }


Lo que pasa es que con eso no voy a conseguir traerme la variable NUM_USUARIO del formulario verdad?:

Código HTML:
Ver original
  1. var NUM_USUARIO = document.forms['form1'].elements['NUM_USUARIO'];

Última edición por satjaen; 06/12/2012 a las 18:31
  #10 (permalink)  
Antiguo 07/12/2012, 10:50
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Respuesta: Condiciones y validaciones

He hecho esto, pero no me hace document.forms['form1'].submit();
Código HTML:
Ver original
  1. <input type="hidden" name="NUM_USUARIO" id="NUM_USUARIO" value="<?php echo $row_Recordset1['NUM_USUARIO'];?>">
Código HTML:
Ver original
  1. function NuevoAviso(){
  2.    
  3.      var NUM_USUARIO = $('#NUM_USUARIO') .val();
  4.      var APARATO = document.forms['form1'].elements['APARATO'];
  5.  
  6.      if (APARATO.value.length == 0){
  7.  
  8.      alert("¡Insertar el Aparato!");
  9.  
  10.      APARATO.focus();
  11.  
  12.      }else{
  13.      
  14.       if (confirm("¿Nuevo aviso?"))
  15.                 {
  16.    
  17.     alert("¡Enviado!");
  18.    document.forms['form1'].submit();//// AQUÍ NO ME MANDA EL INSERT DEL form1
  19.    window.location ="menu8.php?id="+NUM_USUARIO;////AQUÍ YA SI ME LO HACE BIEN
  20.                 }
  21.                 else
  22.                 {
  23.     alert("¡Cancelado!");
  24.    window.location ="menu3.php?id="+NUM_USUARIO;////AQUÍ YA SI ME LO HACE BIEN
  25.    
  26.                 }
  27.         }
  28. }

Un saludo

Etiquetas: condiciones, validar
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 14:17.