Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/12/2013, 13:35
Avatar de legomolina
legomolina
 
Fecha de Ingreso: junio-2011
Ubicación: Valencia
Mensajes: 165
Antigüedad: 12 años, 10 meses
Puntos: 3
No me lee un objeto

Hola a todos, estaba intentando pasar de una base de datos mysql a php y estos datos almacenarlos en un objeto de javascript para su posterior evaluacion y hasta ahí todo bien pero a la hora de comprobarlos con un evento onkeyup, no funciona. Aquí está la página:
Código HTML:
<?php 
	include("/conexiones/programa_satbalma.php");
	$i=0;	
	$sql="SELECT *
		  FROM prueba";
	$res=$db->query($sql);
	while($resultado=mysqli_fetch_row($res)) {
		$art="articulo_".$i;
		echo $art;
		echo "<script languaje='javascript'>";
		echo "var lista={".$art.":{cod:'".$resultado[0]."',nom:'".$resultado[1]."',pvp:'".$resultado[2]."'}};";
		echo "</script>";
		$i++;
	}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Documento sin título</title>
<script language="javascript">
function cod(codigo) {
	var i=0;
	for(i=0;i<20;i++) {
		var art="articulo_"+i;
		if(lista[art][cod]==codigo.value) {
			document.getElementById('nom').innerHTML=lista[art][nom];
			break;
		}
	}
}
</script>
</head>
<body>
<table>
	<tr>
    	<th width="100px">
        	Codigo
        </th>
        <th width="100px">
        	Nombre
        </th>
		<th width="100px">
        	PVP
        </th>
    </tr>
	<tr>
    	<td><input type="text" name="text" id="text" onkeyup="cod(this)"></td>
        <td id="nom"></td>
        <td id="pvp"></td>
    </tr>
</table>
</body>
</html> 
La base de datos solo contiene una tabla llamada prueba con los campos cod, nom y pvp que son los que quiero evaluar.
No se donde está el error. Si pudiesen resolverlo les estaría agradecido.
Atentamente,
Cristian Molina