Foros del Web » Programando para Internet » Javascript »

[SOLUCIONADO] No me funciona código.

Estas en el tema de No me funciona código. en el foro de Javascript en Foros del Web. Hola, por favor tengo este código que me sirve para hacer facturas de clientes. Lo que hago es ingresar datos mediante unas filas que voy ...
  #1 (permalink)  
Antiguo 20/03/2013, 03: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
No me funciona código.

Hola, por favor tengo este código que me sirve para hacer facturas de clientes. Lo que hago es ingresar datos mediante unas filas que voy añadiendo. En las filas hay un campo llamado recambio. En este campo hago un autocompletado y abro una ventana popup pulsando la tecla enter y llamo al código buscar_recambio.php en el que con la funcion volver paso de una ventana a otra unas variables. La primera fila me funciona perfectamente. El problema lo tengo cuando añado la segunda fila que no me hace la funcion volver1 del código buscar_recambio1.php. No se si me he explicado....
Código Javascript:
Ver original
  1. <title>Documento sin título</title>
  2. <script>
  3. $(function() {
  4.        
  5.         <?php
  6.        
  7. include("conexion_autocompletado.php");//se incluyen los datos para realizar la conexion a su base de datos
  8. $con ="SELECT recambio
  9. FROM almacen000"; //consulta para seleccionar las palabras a buscar, esto va a depender de su base de datos//consulta para seleccionar las palabras a buscar, esto va a depender de su base de datos
  10. $query = mysql_query($con);
  11.        
  12.         while($row= mysql_fetch_array($query)) {//se reciben los valores y se almacenan en un arreglo
  13.        
  14.       $elementos[]= '"'.$row['recambio'].'"';
  15.      
  16.         }
  17.    
  18. $arreglo= implode(", ", $elementos);//junta los valores del array en una sola cadena de texto
  19.         ?>    
  20.         var availableTags=new Array(<?php echo $arreglo; ?>);//imprime el arreglo dentro de un array de javascript
  21.         $( "#recambio").autocomplete({
  22.             minLength: 2,
  23.             source: availableTags
  24.         });
  25.        
  26.    
  27.      $(document).keypress(function(e){
  28.                 switch(e.which)
  29.                 {
  30.                     case 13:  nuevo_cliente(); ///// Enter /////
  31.                              break;
  32.                 }
  33.             });    
  34.        
  35.     });    
  36.    
  37. var popup = null;
  38.         function nuevo_cliente(recambio)
  39.         {
  40.             // Si el popup ya existe lo cerramos
  41.             if(popup!=null)
  42.                 popup.close();
  43.  
  44.             // Capturamos las dimensiones de la pantalla para centrar el popup
  45.             altoPantalla = parseInt(screen.availHeight);
  46.             anchoPantalla = parseInt(screen.availWidth);
  47.            
  48.             // Calculamos el centro de la pantalla
  49.             centroAncho = parseInt((anchoPantalla/2))
  50.             centroAlto = parseInt((altoPantalla/2))
  51.    
  52.             // dimensiones del popup
  53.             anchoPopup = 500;
  54.             altoPopup = 200;
  55.  
  56.             // Calculamos las coordenadas de colocación del Popup
  57.             laXPopup = centroAncho - parseInt((anchoPopup/2))
  58.             laYPopup = centroAlto - parseInt((altoPopup/2))
  59.            
  60.            
  61.             var recambio = $('#recambio') .val();
  62.    
  63.    
  64.             // Definimos que página vamos a ver
  65.             pagina = "buscar_recambio.php?id=" +recambio;
  66.            
  67.             popup = window.open(pagina,"Imagenes","scrollbars=yes,status=no,width=" + anchoPopup + ", height=" + altoPopup + ",left = " + laXPopup + ",top = " + laYPopup);
  68.    
  69. }
  70.  
  71. function agregar() {
  72.    
  73.     var contLin = 3;
  74.     var tr, td, tabla;
  75.  
  76.     tabla = document.getElementById('tabla');
  77.     tr = tabla.insertRow(tabla.rows.length);
  78.     td = tr.insertCell(tr.cells.length);
  79.     td.innerHTML = "<input name='button' type=button onclick='agregar3()' value='+' >";
  80.     td = tr.insertCell(tr.cells.length);
  81.     td.innerHTML = "<input name='button' type=button onclick='borrarUltima()' value='-' >";
  82.     td = tr.insertCell(tr.cells.length);
  83.     td.innerHTML = "<input type='text' value='' size='5' >";
  84.     td = tr.insertCell(tr.cells.length);
  85.     td.innerHTML = "<input type='text' name='recambio1' id='recambio1' size='10' >";
  86.     td = tr.insertCell(tr.cells.length);
  87.     td.innerHTML = "<input type='text' name='denominacion1' id='denominacion1' value='' size='25' >";
  88.     td = tr.insertCell(tr.cells.length);
  89.     td.innerHTML = "<input type='text' name='cantidad1' onclick='calcular()' value='' size='5' >";
  90.     td = tr.insertCell(tr.cells.length);
  91.     td.innerHTML = "<input type='text' name='pvp1' id='pvp1' onclick='calcular()' value='' size='5' >";
  92.     td = tr.insertCell(tr.cells.length);
  93.     td.innerHTML = "<input type='text' name='descuento1' onclick='calcular()' value='' size='5' >";
  94.     td = tr.insertCell(tr.cells.length);
  95.     td.innerHTML = "<input type='text' name='total1' onclick='calcular()' value='' size='5' >";
  96.     td = tr.insertCell(tr.cells.length);
  97.     td.innerHTML = "<img src='imagenes_menu/untitled.png' width='20' height='20' style='cursor:pointer' />";
  98.     contLin++;
  99.    
  100. function borrarUltima() {
  101.    ultima = document.all.tabla.rows.length - 1;
  102.    if(ultima > -1){
  103.       document.all.tabla.deleteRow(ultima);
  104.       contLin--;
  105.    }
  106. }    
  107.    
  108.  
  109. $(function() {
  110.        
  111.         <?php
  112.        
  113. include("conexion_autocompletado.php");//se incluyen los datos para realizar la conexion a su base de datos
  114. $con1 ="SELECT recambio
  115. FROM almacen000"; //consulta para seleccionar las palabras a buscar, esto va a depender de su base de datos//consulta para seleccionar las palabras a buscar, esto va a depender de su base de datos
  116. $query = mysql_query($con1);        
  117.        
  118.         while($row= mysql_fetch_array($query)) {//se reciben los valores y se almacenan en un arreglo
  119.        
  120.       $elementos1[]= '"'.$row['recambio'].'"';
  121.      
  122. }
  123. $arreglo1= implode(", ", $elementos1);//junta los valores del array en una sola cadena de texto
  124.  
  125.         ?>    
  126.        
  127.         var availableTags=new Array(<?php echo $arreglo1; ?>);//imprime el arreglo dentro de un array de javascript
  128.                
  129.         $( "#recambio1").autocomplete({
  130.             minLength: 2,
  131.             source: availableTags
  132.         });
  133.        
  134.    
  135.      $(document).keypress(function(e){
  136.                 switch(e.which)
  137.                 {
  138.                     case 13:  nuevo_cliente1(); ///// Enter /////
  139.                              break;
  140.                 }
  141.             });    
  142.        
  143.     });    
  144.    
  145. var popup = null;
  146.         function nuevo_cliente1(recambio)
  147.         {
  148.             // Si el popup ya existe lo cerramos
  149.             if(popup!=null)
  150.                 popup.close();
  151.  
  152.             // Capturamos las dimensiones de la pantalla para centrar el popup
  153.             altoPantalla = parseInt(screen.availHeight);
  154.             anchoPantalla = parseInt(screen.availWidth);
  155.            
  156.             // Calculamos el centro de la pantalla
  157.             centroAncho = parseInt((anchoPantalla/2))
  158.             centroAlto = parseInt((altoPantalla/2))
  159.    
  160.             // dimensiones del popup
  161.             anchoPopup = 500;
  162.             altoPopup = 200;
  163.  
  164.             // Calculamos las coordenadas de colocación del Popup
  165.             laXPopup = centroAncho - parseInt((anchoPopup/2))
  166.             laYPopup = centroAlto - parseInt((altoPopup/2))
  167.            
  168.            
  169.             var recambio = $('#recambio1') .val();
  170.    
  171.    
  172.             // Definimos que página vamos a ver
  173.             pagina = "buscar_recambio1.php?id=" +recambio;
  174.            
  175.             popup = window.open(pagina,"Imagenes","scrollbars=yes,status=no,width=" + anchoPopup + ", height=" + altoPopup + ",left = " + laXPopup + ",top = " + laYPopup);
  176.    
  177.         }
  178.   }
  179.  
  180. </script>
  181. </head>
  182. <body>
  183. <form name="frm" id="frm">
  184. <tr>
  185.     <td>Dto</td>
  186.     <td colspan="2"><label for="base"></label>
  187.       <input name="descuento1" id="descuento1" type="text" disabled="disabled" size="4" /></td>
  188.   </tr>
  189.   <tr>
  190.     <td>Base</td>
  191.     <td colspan="2"><label for="base"></label>
  192.       <input name="base" id="base" type="text" disabled="disabled" size="4" /></td>
  193.   </tr>
  194.   <tr>
  195.     <td >Iva 21%</td>
  196.     <td colspan="2" ><label for="iva"></label>
  197.       <input name="iva" id="iva" disabled="disabled" type="text" size="4" /></td>
  198.   </tr>
  199.   <tr >
  200.     <td class="enlace9">Total</td>
  201.     <td colspan="2" class="enlace9"><label for="total_fact"></label>
  202.       <input name="total_fact" id="total_fact" disabled="disabled" type="text" size="4" /></td>
  203.   </tr>
  204.   <div class="factura" id="factura">
  205. <div class="albaran">
  206. <table id="tabla">
  207. <tr class="cab_factura">
  208.      <td class="enlace10"></td>
  209.     <td class="enlace10"></td>
  210.     <td class="enlace10">Almacén</td>
  211.     <td class="enlace10">Referencia</td>
  212.     <td class="enlace10">Descripción</td>
  213.     <td class="enlace10">Cantidad</td>
  214.     <td class="enlace10">Precio</td>
  215.     <td class="enlace10">%Dto.</td>
  216.     <td class="enlace10">Importe</td>
  217.     <td class="enlace10"></td>
  218.   </tr>
  219.  
  220. <tr>
  221.    <td><input name="button" type=button onclick="agregar();" value="+"  /></td>
  222.    <td><input name="button" type=button onclick="borrarUltima();" value="-"/></td>
  223.     <td ><input name="almacen" type="text" size="5"  /></td>
  224.     <td><input name="recambio" id="recambio" type="text" size="10"/></td>
  225.     <td><input name="denominacion" type="text" size="25"/></td>
  226.     <td><input name="cantidad" id"cantidad" type="text" size="5" onkeyup="calcular()"  /></td>
  227.     <td><input name="pvp" id"pvp" type="text" size="5" onkeyup="calcular()"   /></td>
  228.     <td><input name="descuento" id"descuento" type="text" size="5" onkeyup="calcular()"  /></td>
  229.     <td><input name="total" id"total" type="text" size="5" onkeyup="calcular()"  /></td>
  230.     <td><img src="imagenes_menu/untitled.png" onclick="" width="20" height="20" style="cursor:pointer" /></td>
  231.   </tr>  
  232. </table>
  233. </form>
  234. </body>
  235. </html>

Gracias
  #2 (permalink)  
Antiguo 20/03/2013, 03:34
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: No me funciona código.

Y estos lo php:

buscar_recambio.php

Código PHP:
<?php require_once('Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
$recambio=$_GET['id'];
mysql_select_db($database_conexion$conexion);
$query_Recordset1 "SELECT * FROM almacen000 where recambio='$recambio'";
$Recordset1 mysql_query($query_Recordset1$conexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento sin título</title>
<style type="text/css">
#apDiv1 {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 1;
}
</style>
<script>
function volver() {
window.opener.document.frm.recambio.value = document.myform.recambio.value;
window.opener.document.frm.denominacion.value = document.myform.denominacion.value;
window.opener.document.frm.pvp.value = document.myform.pvp.value;
window.close();
}
</script>
</head>
<body>
<div id="apDiv1">
<table width="100%" border="1">
<form id="myform" name="myform" action="" method="post">
  <tr>
    <td>Almacén</td>
    <td>Referencia</td>
    <td>Descripción</td>
     <td>PVP</td>
    <td>Stock</td>
  </tr>
  <tr>
    <td><?php echo $row_Recordset1['almacen']; ?></td>
    <td><input type="text" size= "9" name="recambio" value="<?php echo $row_Recordset1['recambio']; ?>"/></td>
    <td><input type="text" size= "9" name="denominacion" value="<?php echo $row_Recordset1['denominacion']; ?>"/></td>
    <td><input type="text" size= "9" name="pvp" value="<?php echo $row_Recordset1['pvp']; ?>"/></td>
    <td><?php echo $row_Recordset1['existencias']; ?></td>
  </tr>
</table>
<a href="javascript:volver();" title="pasar valor">Regresar a la Ventana Principal</a>
</form>
</div>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
buscar_recambio1.php

Código PHP:
<?php require_once('Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
$recambio=$_GET['id'];
mysql_select_db($database_conexion$conexion);
$query_Recordset1 "SELECT * FROM almacen000 where recambio='$recambio'";
$Recordset1 mysql_query($query_Recordset1$conexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento sin título</title>
<style type="text/css">
#apDiv1 {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 1;
}
</style>
<script>
function volver1(recambio,denominacion,pvp) {
window.opener.document.myform1.idrecambio1.value = recambio;
window.opener.document.myform1.iddenominacion1.value = denominacion;
window.opener.document.myform1.idpvp1.value = pvp;
window.close();
}
</script>
</head>
<body>
<div id="apDiv1">
<table width="100%" border="1">
<form id="myform1" name="myform1" action="" method="post">
  <tr>
    <td>Almacén</td>
    <td>Referencia</td>
    <td>Descripción</td>
     <td>PVP</td>
    <td>Stock</td>
  </tr>
  <tr>
    <td><?php echo $row_Recordset1['almacen']; ?></td>
    <td><input type="text" size= "9" name="recambio" id="recambio" value="<?php echo $row_Recordset1['recambio']; ?>"/></td>
    <td><input type="text" size= "9" name="denominacion" id="denominacion" value="<?php echo $row_Recordset1['denominacion']; ?>"/></td>
    <td><input type="text" size= "9" name="pvp" id="pvp" value="<?php echo $row_Recordset1['pvp']; ?>"/></td>
    <td><?php echo $row_Recordset1['existencias']; ?></td>
  </tr>
</table>
<a href="javascript:volver1();" title="pasar valor">Regresar a la Ventana Principal</a>
</form>
</div>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
Gracias
  #3 (permalink)  
Antiguo 20/03/2013, 04:58
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: No me funciona código.

Ok,

Código Javascript:
Ver original
  1. <script>
  2. function volver1() {
  3. window.opener.document.getElementById('recambio1').value = document.myform.recambio.value;
  4. window.opener.document.getElementById('denominacion1').value = document.myform.denominacion.value;
  5. window.opener.document.getElementById('pvp1').value = document.myform.pvp.value;
  6. window.close();
  7. }
  8. </script>

Gracias

Etiquetas: funcion, html, input, php, select
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 23:31.