Ciao ragazzi,
sto utilizzando questo javascript:
codice:
function toggleLayer( whichLayer )
{
var elem, vis;
if( document.getElementById ) // this is the way the standards work
elem = document.getElementById( whichLayer );
else if( document.all ) // this is the way old msie versions work
elem = document.all[whichLayer];
else if( document.layers ) // this is the way nn4 works
elem = document.layers[whichLayer];
vis = elem.style;
// if the style.display value is blank we try to figure it out here
if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
e questa routine:
codice:
$result=mysql_query("
SELECT *
FROM tabella
ORDER BY nome ASC
");
while ($row = mysql_fetch_array($result)){
$nome = $row['nome'];
echo "<a href =\"javascript:toggleLayer('commentForm');\">$nome</a><div id=\"commentForm\">CIAO</div>";
}
Quando carico la pagina, mi vengono elencate tutte le righe presenti nella tabella e mi appare una serie di nomi come link, ma solo il primo $nome (il primo link prodotto) sembra essere seguito dal DIV
"commentForm".
Tutti i successivi link fanno apparire o scomparire sempre e solo il DIV posto sotto il primo risultato.
Questo penso sia dovuto al fatto che tutti i div prodotti dalla routine hanno come id "commentForm".
Come posso modificare la routine in modo da ottenere un DIV diverso per ogni link?
Si potrebbe aggiungere un nome progressivo ai risultato PHP, ma non posso modificare il javascript.
Qualcuno ha risolto un problema simile in qualche modo?
grazie