<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>aggiungi / rimuovi campi input</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showList(pagina) {
sList = window.open(pagina, "list", "width=650,height=250 ,scrollbars=yes");
}
function remLink() {
if (window.sList && !window.sList.closed)
window.sList.opener = null;
}
// -->
</SCRIPT>
<script language="JavaScript" type="text/javascript">
<!--
var num=1;
var num2;
var num3;
function accoda(){
if(document.createElement && document.getElementById && document.getElementsByTagName) {
// crea elementi
var oTr=document.createElement("TR");
var oTd1=document.createElement("TD");
var oTd2=document.createElement("TD");
var oField=document.createElement("INPUT");
var oField2=document.createElement("INPUT");
var oField3=document.createElement("INPUT");
var oButt=document.createElement("INPUT");
// setta attributi
oField.setAttribute("type","text");
oField.setAttribute("name","inv"+num);
oField.setAttribute("value",+num+1);
oField.setAttribute("size",3);
oField2.setAttribute("type","text");
oField2.setAttribute("name","prodotto"+num);
oField3.setAttribute("type","text");
oField3.setAttribute("name","prodotto2"+num);
oButt.setAttribute("type","button");
oButt.setAttribute("value","rimuovi");
// setta gestore evento
if( oField3.attachEvent ){
oField3.attachEvent('onclick', 'showList2');
} else {
oField.setAttribute('onclick', 'window.open("dett_fatture.php?a1=" + num , "list", "width=650,height=250 ,scrollbars=yes");');
}
if(oButt.attachEvent) oButt.attachEvent('onclick',function(e){rimuovi(e) ;})
else
if(oButt.addEventListener) oButt.addEventListener('click',function(e){rimuovi (e);},false)
// appendi al relativo padre
oTd1.appendChild(oField);
oTd1.appendChild(oField2);
oTd1.appendChild(oField3);
oTd2.appendChild(oButt);
oTr.appendChild(oTd1);
oTr.appendChild(oTd2);
document.getElementById('tabella').getElementsByTa gName('TBODY')[0].appendChild(oTr);
// incrementa variabile globale
num++
}
}
function rimuovi(e){
if(document.removeChild && document.getElementById && document.getElementsByTagName) {
if(!e) e=window.event;
var srg=(e.target)?e.target:e.srcElement;
// risali al tr del td che contiene l' elemento che ha scatenato l' evento
while(srg.tagName!="TR"){srg=(srg.parentNode)?srg. parentNode:srg.parentElement}
// riferimento al tbody
var tb=document.getElementById('tabella').getElementsB yTagName('TBODY')[0];
// rimuovi
tb.removeChild(srg);
}
}
//-->
</script>
</head>
<body>
<form name="modulo" method="Get">
<input type="button" value="accoda" onclick="accoda()" /><input type="submit" />
<table border="1" id="tabella">
<tbody>
<tr>
<td><input type="text" name="prodotto"SIZE="3" value="1" />
questo è il mio script
<INPUT TYPE="text" NAME="stockBox1" VALUE='22'onClick="showList('dett_fatture.php?a1=' +document.invia.inv2.value)">
<input type="text" value="qui" name="inv" onClick="showList('dett_fatture.php?a='+document.m odulo.prodotto.value,document.modulo.inv.value)">
</td><td><input type="button" disabled="disabled" value="rimuovi" /></td>
</tr>
<tr>
<td>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Mi crea dinamicamente gli input e ogni volta che clicco su uno di essi mi apre il popup e mi ricarica i dati come ne tuo esempio.
il mio problema è il seguente:
Se il clicco sul 3 input come posso mandare la riga relativa al terzo input al popup?
devo identificare quale input mi ha generato onclick
grazie.