Foros del Web » Programando para Internet » Javascript »

sigo con el problema del bucle

Estas en el tema de sigo con el problema del bucle en el foro de Javascript en Foros del Web. todavía sigo con el problema he variado mi función a : tablaInicio += ("<table border=1 align=center>") for (var i = 0; i < elems.length; i ...
  #1 (permalink)  
Antiguo 14/05/2005, 04:32
 
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 83
Antigüedad: 20 años, 8 meses
Puntos: 0
sigo con el problema del bucle

todavía sigo con el problema he variado mi función a :

tablaInicio += ("<table border=1 align=center>")
for (var i = 0; i < elems.length; i ++)
{
img += ("<tr>")
for (var j = 0; j < 3; j++)
{
var el = elems.item(i)
ruta = el.getAttribute("ruta");
titulo = el.getAttribute("titulo");
alt = el.getAttribute("alt");
var evento = 'O['+i+'].clic()';
precio = el.getAttribute("precio");
embalaje = el.getAttribute("embalaje");
codigo = el.getAttribute("id");
datos +=("Precio : " + precio + "&nbsp;&nbsp;" + "Embalaje : " + embalaje + "<br>")
inputs += ("<input type='text' maxlength='10' value='1' name=text_" + codigo + " size='8' onClick='msg()'>&nbsp;&nbsp;<a href='resultado.htm' target='_blank'>Enviar Carro</a>")
img+=("<td>" + titulo + "<br><br><img onclick=" + evento + " class=img height=225 width=300 src=" + ruta + "><br>" + datos + inputs +"</td>");
datos = "";
inputs = "";
}
img += ("</tr>")
}

tablaFin += ("</table>")


y lo que me hace ahora es cargarme las fotos 9 filas y tres columnas repitiendo por fila cuando lo que yo quiero es cargar las 9 fotos en una tabla en tres columnas, pero sin saber cuantas fotos voy a tener las recupero de un fichero y lo quiero cargar en la tabla dinámicamente

Pro favor que alguien me pueda ayudar gracias
JAime
  #2 (permalink)  
Antiguo 14/05/2005, 05:37
 
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 83
Antigüedad: 20 años, 8 meses
Puntos: 0
Para quien le interesa ya lo he solucionado haciendo esto:

tablaInicio += ("<table border=1 align=center width=90%>")
for (var i = 0; i < elems.length; i ++)
{
if ((i % 3) == 0)
{
img += ("<tr>");
}
var el = elems.item(i)
ruta = el.getAttribute("ruta");
titulo = el.getAttribute("titulo");
alt = el.getAttribute("alt");
var evento = 'O['+i+'].clic()';
precio = el.getAttribute("precio");
embalaje = el.getAttribute("embalaje");
codigo = el.getAttribute("id");
datos +=("Código : " + "<strong>" + codigo + "</strong><br> Precio : " + precio + "&nbsp;&nbsp;" + "Embalaje : " + embalaje + "<br>")
inputs += ("<input type='text' maxlength='10' value='1' name=text_" + codigo + " size='8' onClick='msg()'>&nbsp;&nbsp;<a href='resultado.htm' target='_blank'>Enviar Carro</a>")
img+=("<td>" + titulo + "<br><br><img onclick=" + evento + " class=img height=225 width=300 src=" + ruta + "><br>" + datos + inputs +"</td>");
datos = "";
inputs = "";
aux = aux + 1;

if (aux == 3)
{
img += ("<tr>");
aux = 0;
}
}

tablaFin += ("</table>")
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:19.