Javascript Variables - Select and Mix -
i have 2 3 variables want mix strings , place them table, can't figure out how make variables mix.
what have
document.write('<table cellspacing="0" cellpadding="5">') var = ["string1", "string2"] var n = ["string3", "string4"] for(var i=0; <a.length; i++){ document.write('<tr'> document.write('td' + (a[i]) + (b[i]) +'</td>') document.write('</td>') } document.write('</table>')
this create table want doesn't perform function looking for.
it creates table goes:
"string1" "string3"
"string2" "string4'
i'm looking for:
"string1" "string3"
"string1" "string4"
"string2" "string3"
"string2" "string4"
hopefully makes sense. i've tried searching through internet , on stack overflow no avail. how make happen? arrays should able grow maybe hundred each...
you need additional loop -
for(var = 0; < a.length; i++) { (var j = 0; j < b.length; j++) { document.write('<tr'>); document.write('<td>' + a[i] + b[j] + '</td>'); document.write('</td>'); } }
p.s.: need create elements using document.write
? it's ok if it's example, style of element creation discouraged in real development code.
Comments
Post a Comment