salve,
ho un problema che non riesco a risolvere, probabilmente per la mia scarsa conoscenza di javascript.
Spiego di che si tratta:
Ho due funzioni trovate in rete che mi aggiungono o mi tolgono una serie di tasti...
<script type="text/javascript">
function addRow(){
var nForm = document.forms[0];
var nClone = nForm.getElementsByTagName('table')[0].cloneNode(true);
var nFloor = document.getElementById('floor');
nForm.insertBefore(nClone,nFloor);
var nTable = document.getElementsByTagName('table');
nTable[nTable.length-1].getElementsByTagName('td')[0].firstChild.data = nTable.length;
var nField = nTable[nTable.length-1].getElementsByTagName('input');
for (i=0; i<nField.length; i++)
{
nField[i].value = "";
}
}
function removeRow(){
var nForm = document.forms[0];
var nTable = nForm.getElementsByTagName('table');
var lastTable = nTable[nTable.length-1];
if (nTable.length > 1)
{
nForm.removeChild(lastTable);
}
}
</script>
Il contenuto del form è il seguente...
<form action="prova2.asp?save=<%="yes"%>" method="post" >
<table>
<tr>
<td><INPUT type="checkbox" style="font-family:tahoma; font-size:11px; margin-right:3px" id="key" name="Key_[]"> </td>
<td><input type="text" maxlength=25 size=25 style="font-family:tahoma; font-size:11px; margin-right:3px" name="fld_[]"></td>
<td>
<select size=1 style="font-family:tahoma; font-size:11px; margin-left:17px " id="type" name="typ_[]" onchange="javascript:KeyCliK();" >
<%
dim RSType
set RSType = Server.CreateObject("ADODB.RECORDSET")
RSType.ActiveConnection=Objconn
RSType.Open("select * from sys.systypes order by name")
Response.Write("<option selected>Scegli un data type</option>")
while not RSType.EOF
Response.Write "<option value=" & trim(RSType(0)) & ">" & RSType(0) & "</option>" & vbcrlf
RSType.movenext
wend
RSType.close
set RSType=nothing
%>
</select>
</td>
<td><input type="text" maxlength=8 size=8 style="font-family:tahoma; font-size:11px; margin-right:3px" name="lnt_[]"></td>
<td><input type="text" maxlength=8 size=8 style="font-family:tahoma; font-size:11px; margin-right:3px" name="prc_[]"></td>
<td><input type="text" maxlength=8 size=8 style="font-family:tahoma; font-size:11px; margin-right:3px" name="scl_[]"></td>
<td><input type="text" maxlength=8 size=8 style="font-family:tahoma; font-size:11px; margin-right:3px" name="dft_[]"></td>
<td><INPUT type="checkbox" style="font-family:tahoma; font-size:11px; margin-right:3px" id="null" name="nll_[]" ></td>
<td><INPUT type="checkbox" style="font-family:tahoma; font-size:11px; margin-right:3px" id="identity" name="idt_[]"></td>
<td><input type="text" maxlength=8 size=8 style="font-family:tahoma; font-size:11px; margin-right:3px" id="offset" name="off_[]"></td>
<td><input type="text" maxlength=8 size=8 style="font-family:tahoma; font-size:11px; margin-right:3px" id="increment" name="inc_[]" ></td>
</tr>
</table>
<input type="button" id="floor" value="Aggiungi input" onclick="addRow();">
<input type="button" value="Elimina input" onclick="removeRow();">
<input type="submit" value="Crea">
</form>
Ho poi un'altra funzione javascript che mi setta (o meglio dovrebbe...) determinati valori su alcuni campi nel caso in cui il primo checkbox sia spuntato e il data type (terzo campo del form) sia integer.
Il checkbox spuntato + data type integer significa che siamo in presenza di un campo chiave e quindi automaticamente viene settato il check box "Identity" l'Inizio identity e l'incremento.
Poi vengono disabilitati il checkbox null e il check box identity.
Tutto questo nell'ordine che ho descritto.
La funzione relativa è ...
<script type="text/javascript">
function KeyCliK()
{
if ((document.getElementById('key').checked) && (document.getElementById('type').value) == "int")
{
document.getElementById('identity').checked=true;
document.getElementById('null').checked=false;
document.getElementById('offset').value=1;
document.getElementById('increment').value=1;
document.getElementById('identity').disabled=true;
document.getElementById('null').disabled=true;
}
else
{
document.getElementById('identity').checked=false;
document.getElementById('null').checked=true;
}
}
</script>
Il problema è che quest'ultima funzione funziona - scusate la ripetizione - solo sulla prima serie di campi.
Se io ho aggiunto altre due serie di campi con la funzione add() inizialmente descritta dalla secondsa serie in poi la funzione KeyCliK() non va.
Potete aiutarmi ?
Grazie in anticipo