clematis
06-24-2009, 03:45 PM
hi,
I have tried to solve the problem differently from my previous post (06-22-2009) on which I had no answer.
The problem now is different
The javascript function addRowToTable() is called by a button, and replies a set of elements (select, input, checkbox) of the form.
In this function, the creation of select calls another function CliK(sel.id)
The problem is that this function tells me error "object required" as if the select Id was not "type"
or the checkbox id was not "key"
Where I go wrong?
Posting the complete code
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);
}
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;
}
}
thanks in advance
I have tried to solve the problem differently from my previous post (06-22-2009) on which I had no answer.
The problem now is different
The javascript function addRowToTable() is called by a button, and replies a set of elements (select, input, checkbox) of the form.
In this function, the creation of select calls another function CliK(sel.id)
The problem is that this function tells me error "object required" as if the select Id was not "type"
or the checkbox id was not "key"
Where I go wrong?
Posting the complete code
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);
}
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;
}
}
thanks in advance