|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Jun 2009
Messaggi: 1
|
Problemi con document.createelment
salve,
ho un problema che non riesco a risolvere, probabilmente per la mia scarsa conoscenza di javascript. Spiego di che si tratta: La funzione javascript sottostante richiamata da un tasto, replica tutta la serie di elementi (select, input, checkbox) presenti nel form Nella funzione la select è generata così: function addRowToTable() { var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length; var iteration = lastRow; var row = tbl.insertRow(lastRow); // chk1 cell var cellChk1 = row.insertCell(0); var el = document.createElement("input"); el.type = 'checkbox'; el.name = 'Key' + iteration; el.id = 'Key' + iteration; el.className = 'div'; el.checked=false; el.defaultChecked=false; cellChk1.appendChild(el); // Input1 cell var cellInput1 = row.insertCell(1); var el = document.createElement('input'); el.type = 'text'; el.name = 'fld' + iteration; el.id = 'fld' + iteration; el.className = 'div'; el.size = 8; el.onkeypress = keyPressTest; cellInput1.appendChild(el); // select1 cell var cellSel1 = row.insertCell(2); var sel = document.createElement('select'); sel.name = 'Type' + iteration; sel.id = 'Type' + iteration; <% dim RSType set RSType = Server.CreateObject("ADODB.RECORDSET") RSType.ActiveConnection=Objconn RSType.Open("select * from sys.systypes order by name") Response.Write("sel.options[0] = new Option('scegli un data type', '');") i=1 while not RSType.EOF Response.Write "sel.options[" & i & "] = new Option('" & trim(RSType(0)) & "', '" & trim(RSType(0)) & "');" RSType.movenext i=i+1 wend RSType.close set RSType=nothing %> sel.onchange = CliK(sel.id); sel.className = 'div'; cellSel1.appendChild(sel); // Input2 cell var cellInput2 = row.insertCell(3); var el = document.createElement('input'); el.type = 'text'; el.name = 'lnt' + iteration; el.id = 'lnt' + iteration; el.className = 'div'; el.size = 8; el.onkeypress = keyPressTest; cellInput2.appendChild(el); // Input3 cell var cellInput3 = row.insertCell(4); var el = document.createElement('input'); el.type = 'text'; el.name = 'prc' + iteration; el.id = 'prc' + iteration; el.className = 'div'; el.size = 8; el.onkeypress = keyPressTest; cellInput3.appendChild(el); // Input4 cell var cellInput4 = row.insertCell(5); var el = document.createElement('input'); el.type = 'text'; el.name = 'scl' + iteration; el.id = 'scl' + iteration; el.className = 'div'; el.size = 8; el.onkeypress = keyPressTest; cellInput4.appendChild(el); // Input5 cell var cellInput5 = row.insertCell(6); var el = document.createElement('input'); el.type = 'text'; el.name = 'dft' + iteration; el.id = 'dft' + iteration; el.className = 'div'; el.size = 8; el.onkeypress = keyPressTest; cellInput5.appendChild(el); // chk2 cell var cellChk2 = row.insertCell(7); var el = document.createElement("input"); el.type = 'checkbox'; el.name = 'nll' + iteration; el.id = 'nll' + iteration; el.className = 'div'; el.checked=false; el.defaultChecked=false; cellChk2.appendChild(el); // chk1 cell var cellChk3 = row.insertCell(8); var el = document.createElement("input"); el.type = 'checkbox'; el.name = 'idt' + iteration; el.id = 'idt' + iteration; el.className = 'div'; el.checked=false; el.defaultChecked=false; cellChk3.appendChild(el); // Input6 cell var cellInput6 = row.insertCell(9); var el = document.createElement('input'); el.type = 'text'; el.name = 'off' + iteration; el.id = 'off' + iteration; el.className = 'div'; el.size = 8; el.onkeypress = keyPressTest; cellInput6.appendChild(el); // Input7 cell var cellInput7 = row.insertCell(10); var el = document.createElement('input'); el.type = 'text'; el.name = 'inc' + iteration; el.id = 'inc' + iteration; el.className = 'div'; el.size = 8; el.onkeypress = keyPressTest; cellInput7.appendChild(el); } La funzione richiamata da sel.onchange è la seguente: function CliK(idx) { if ((document.getElementById('Key' + idx).checked) && (document.getElementById('type' + idx).value) == "int") { document.getElementById('idt' + idx).checked=true; document.getElementById('nll' + idx).checked=false; document.getElementById('off' + idx).value=1; document.getElementById('inc' + idx).value=1; document.getElementById('idt' + idx).disabled=true; document.getElementById('lnt' + idx).disabled=true; document.getElementById('nll' + idx).disabled=true; } else { document.getElementById('idt' + idx).checked=false; document.getElementById('nll' + idx).checked=true; } } Il problema è che quest'ultima funzione va in errore e mi dice "Necessario oggetto" come se l'Id della select non fosse "type" o l'id della checkbox non fosse "key" Dov'è che sbaglio? |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
|
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:14.