Cioè te, partendo da una serie di INPUT che non hanno un Kaiser di niente, niente NAME, niente ID e che magari non si sa' neppure quanti sono, vorresti uno SCRIPT che facesse qualcosa del genere ?!?? :
codice:
<html>
<head><title>handling anonymous input's</title>
<script type="text/javascript">
var w;
var lasciato=0;
function apri(dove){
campi[lasciato].style.backgroundColor='';
lasciato=dove;
campi[dove].style.backgroundColor='rgb(255, 255, 190)';
var prevalue = campi[dove].value;
campi[dove].value='loading ...';
w = window.open('', 'same', 'top=0, left=0, width=500, height=300');
w.document.open();
w.document.writeln('<html><head><title>ricerca nel database<\/title>');
w.document.writeln('<sc'+'ript type="text/javascript">');
w.document.writeln('function riporta(){');
w.document.writeln(' window.opener.campi[' + dove + '].value=document.getElementById("risulta").value;');
w.document.writeln(' window.close();');
w.document.writeln(' }');
w.document.writeln('<\/sc'+'ript>');
w.document.writeln('<\/head><body onunload="window.opener.campi[' + dove + '].style.backgroundColor=\\'\\';">');
w.document.writeln('<input id="risulta" size="40" value="Il risultato della ricerca compaia qua">');
w.document.writeln('<input value="riporta" type="button" onclick="riporta()">');
w.document.write('<\/body><\/html>');
w.document.close();
w.focus();
campi[dove].value=prevalue;
}
var campi;
function assegna(){
var celle = document.getElementById("modulo").getElementsByTagName("td");
var i=0;
for(var c=1; c<celle.length; c=c+2){
celle[c].innerHTML='<input onclick="apri(' + i + ');">';
i++;
};
campi = document.getElementById("modulo").getElementsByTagName("input");
}
</script>
</head>
<body bgcolor="gray" onload="assegna()" onunload="w.close()">
<table border="1" align="center"><tr>
<td>
<table id="modulo" bgcolor="silver"><tr>
<td>1</td><td><input></td>
</tr><tr>
<td>2</td><td><input></td>
</tr><tr>
<td>3</td><td><input></td>
</tr><tr>
<td>4</td><td><input></td>
</tr><tr>
<td>5</td><td><input></td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>
P.S. : Vedilo anche sostituendo la function assegna() con la seguente, che però rimane incompatibile con Internet Explorer:
codice:
var campi;
function assegna(){
campi = document.getElementById("modulo").getElementsByTagName("input");
for(i=0; i<campi.length; i++){
campi[i].setAttribute("onclick", "apri(" + i + ");");
};
//alert(document.getElementById("modulo").innerHTML);
}
Concettualmente, assegnando dinamicamente la gestione dell' evento ONCLICK agli INPUT così come esistenti, sarebbe più adatta, ma occorre ricorrere a dei workaround per averla cross-browsers. Il ricorso ad .innerHTML in definitiva, ove non comporti "sconvolgimento" dei contenuti originali, può essere considerato come uno dei workaround possibili; magari un po' più "radicale"