Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/04/2012, 09:47
pablokru
 
Fecha de Ingreso: octubre-2011
Ubicación: Buenos Aires
Mensajes: 84
Antigüedad: 13 años, 3 meses
Puntos: 2
Pregunta Respuesta: Insertar condigo PHP en Javascript en la funcion document.getElementById

Hola, amplio el ejemplo asi se entiende:

Código PHP:
<?php
$i
=1
while ( $i <= 100) {
?>
<div id="<?php echo'resultado'.$i;?>" style="width: 10px"><p>Hola</p></div>
Código:
<script>
var xhr;
function ajax<?=$i?>(){

var pos= <?php echo $i;?>;
    
xhr.open("GET","modificar.php?pos="+pos);
	
	xhr.onreadystatechange=callback; 
	xhr.send();
}
function callback(){
	if(xhr.readyState==4){
		if(xhr.status==200){

document.getElementById("<?php echo'resultado'.$i;?>").style.width = '10px';
		}
	}
}
</script>

Código PHP:
<?php
$i
++;
}
?>
Si yo en document.getElementById escribo entre parentesis resultado1 o resultado2 o resultado97 funciona. El problema es que no funciona cuando coloco ("<?php echo'resultado'.$i;?>")