Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/04/2011, 16:26
erxaca
 
Fecha de Ingreso: enero-2010
Mensajes: 389
Antigüedad: 14 años, 3 meses
Puntos: 4
Variable undefined

Hola compañeros,

haber si me podeis echar un cable y decirme porque me dice que la variable imgbebida no esta definida:

JS
Código HTML:
	var j = 0;
	var bebidas = new Array(10);
	var altbebidas = new Array(10);
	var namebebidas = new Array(10);
    function cambiarValores(obj, prod) { //Recibimos el objeto y el nombre de la bebida
      var img = obj.src, k;
	  img = img.split('/').pop();
      img = img == 'boton-bebidas-' + obj.alt + '-off.png' ? 'images/boton-bebidas-' + obj.alt + '-on.png' : 'images/boton-bebidas-' + obj.alt + '-off.png';
      obj.src = img;
	  for(i=0;i<10;i++) {
	    if(bebidas[i] == prod) {
		  var bebida = bebidas[i];
		  var altbebida = altbebidas[i];
          var imgbebida = document.getElementsByName(bebida)[0];
		  imgbebida.src = 'images/boton-bebidas-' + altbebida + '-off.png';
	    }
		var conta = 0;
		for(k=0;k<10;k++){if(i!=k){conta++;}}
		if(conta==10){i++;}
	  }
	  bebidas[j] = prod;
	  altbebidas[j] = obj.alt
	  namebebidas[j] = obj.name;
}
HTML
Código HTML:
 <td>
	              <img src="images/boton-bebidas-1-off.png" name="c1" alt="1" onclick="cambiarValores(this,'CocaCola')" />
	              <input type="hidden" name="coca-cola-1" value="bebida" />
	            </td>
	            <td>
	              <img src="images/boton-bebidas-2-off.png" name="c2" alt="2" onclick="cambiarValores(this,'CocaCola')" />
	              <input type="hidden" name="coca-cola-2" value="bebida" />
	            </td>
	          </tr> 

Saludos ;)