Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/11/2011, 16:50
Avatar de pampa_
pampa_
 
Fecha de Ingreso: mayo-2006
Mensajes: 334
Antigüedad: 18 años, 9 meses
Puntos: 1
pasar variable php a javascript

Hola a todos!!

Quiero pasar una variable php a javascript, y luego en poder sacar el resultado de esa variable.... he hecho esto, pero no me sirve me devuelve "undefined"....

Código Javascript:
Ver original
  1. <script language="JavaScript" type="text/JavaScript">
  2.  
  3. var anuncio0 = new Array(5);
  4. var anuncio1 = new Array(5);
  5. var anuncio2 = new Array(5);
  6.  
  7. var anuncios = new Array (3)
  8. anuncios[0] = anuncio0;
  9. anuncios[1] = anuncio1;
  10. anuncios[2] = anuncio2;
  11.  
  12. var counter = 0;
  13. function rellenar(){
  14.                 if('.$i.'==0){     
  15.                     anuncio0[0] = new Image(62,12);
  16.                     anuncio0[0] = "'.$row[4].'";
  17.                     anuncio0[1] = "'.$mayusculas.'";
  18.                     anuncio0[2] = "'.$row[3].'";
  19.                     anuncio0[3] = "'.$categoriamayusculas.'";
  20.                     anuncio0[4] = "'.$preciomayusculas.'";
  21.                 }else if('.$i.'==1){
  22.                     anuncio1[0] = new Image(62,12);
  23.                     anuncio1[0] = "'.$row[4].'";
  24.                     anuncio1[1] = "'.$mayusculas.'";
  25.                     anuncio1[2] = "'.$row[3].'";
  26.                     anuncio1[3] = "'.$categoriamayusculas.'";
  27.                     anuncio1[4] = "'.$preciomayusculas.'";
  28.                 }else{
  29.                     anuncio2[0] = new Image(62,12);
  30.                     anuncio2[0] = "'.$row[4].'";
  31.                     anuncio2[1] = "'.$mayusculas.'";
  32.                     anuncio2[2] = "'.$row[3].'";
  33.                     anuncio2[3] = "'.$categoriamayusculas.'";
  34.                     anuncio2[4] = "'.$preciomayusculas.'";
  35.                 }
  36.                
  37.     }
  38.  
  39. function changeBanner(){
  40.     if(counter > 2)
  41.       counter = 0;
  42. document.getElementById("banner").innerHTML = "<img src="+anuncios[counter][0]+" width='62px' height='12px' border='0px' />"
  43. document.getElementById("texto").innerHTML = anuncios[counter][2];
  44. document.getElementById("banner_peq_5").style.background="white";
  45. document.getElementById("banner_peq_"+(counter+1)).style.background="red";
  46.     if (counter >= 1)
  47. document.getElementById("banner_peq_"+counter).style.background="white";    
  48.       counter++;
  49.     }
  50.  
  51.  
  52. timer = setInterval("changeBanner()", 2000);
  53. window.onload = changeBanner;
  54.  
  55. </script>

despues lo llamo
Código HTML:
Ver original
  1. <script language="javascript" type="text/javascript">
  2.             rellenar()
  3.                     alert(anuncios[0][1]);
  4.                     alert(anuncios[0][3]);
  5.                     alert(anuncios[1][1]);
  6.                 </script>