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<script language="JavaScript" type="text/JavaScript">
var anuncio0 = new Array(5);
var anuncio1 = new Array(5);
var anuncio2 = new Array(5);
var anuncios = new Array (3)
anuncios[0] = anuncio0;
anuncios[1] = anuncio1;
anuncios[2] = anuncio2;
var counter = 0;
function rellenar(){
if('.$i.'==0){
anuncio0[0] = new Image(62,12);
anuncio0[0] = "'.$row[4].'";
anuncio0[1] = "'.$mayusculas.'";
anuncio0[2] = "'.$row[3].'";
anuncio0[3] = "'.$categoriamayusculas.'";
anuncio0[4] = "'.$preciomayusculas.'";
}else if('.$i.'==1){
anuncio1[0] = new Image(62,12);
anuncio1[0] = "'.$row[4].'";
anuncio1[1] = "'.$mayusculas.'";
anuncio1[2] = "'.$row[3].'";
anuncio1[3] = "'.$categoriamayusculas.'";
anuncio1[4] = "'.$preciomayusculas.'";
}else{
anuncio2[0] = new Image(62,12);
anuncio2[0] = "'.$row[4].'";
anuncio2[1] = "'.$mayusculas.'";
anuncio2[2] = "'.$row[3].'";
anuncio2[3] = "'.$categoriamayusculas.'";
anuncio2[4] = "'.$preciomayusculas.'";
}
}
function changeBanner(){
if(counter > 2)
counter = 0;
document.getElementById("banner").innerHTML = "<img src="+anuncios[counter][0]+" width='62px' height='12px' border='0px' />"
document.getElementById("texto").innerHTML = anuncios[counter][2];
document.getElementById("banner_peq_5").style.background="white";
document.getElementById("banner_peq_"+(counter+1)).style.background="red";
if (counter >= 1)
document.getElementById("banner_peq_"+counter).style.background="white";
counter++;
}
timer = setInterval("changeBanner()", 2000);
window.onload = changeBanner;
</script>
despues lo llamo
Código HTML:
Ver original<script language="javascript" type="text/javascript"> rellenar()
alert(anuncios[0][1]);
alert(anuncios[0][3]);
alert(anuncios[1][1]);