PHP gevorderde |
|
In plaats van wat er nu op regel 11 staat:
var tbl = document.getElementById("texts");
// stop nieuwe rij in tabel
var newTR = tbl.insertRow(tbl.rows.length);
// stop 3 nieuwe cellen in de nieuwe rij
for(var arrTD = new Array(3), i = 0; i < arrTD.length; i++)
arrTD[i] = newTR.insertCell(newTR.cells.length);
// vul cellen in
arrTD[0].innerHTML = noTexts + '.';
arrTD[1].innerHTML = '<input type="text" name="text-' + noTexts + '" id="text-' + noTexts + '" tabindex="' + noTexts + '">';
arrTD[2].innerHTML = '<input type="checkbox" name="greek-' + noTexts + '" id="greek-' + noTexts+ '">';
var tbl = document.getElementById("texts"); // stop nieuwe rij in tabel var newTR = tbl.insertRow(tbl.rows.length); // stop 3 nieuwe cellen in de nieuwe rij for(var arrTD = new Array(3), i = 0; i < arrTD.length; i++) arrTD[i] = newTR.insertCell(newTR.cells.length); // vul cellen in arrTD[0].innerHTML = noTexts + '.'; arrTD[1].innerHTML = '<input type="text" name="text-' + noTexts + '" id="text-' + noTexts + '" tabindex="' + noTexts + '">'; arrTD[2].innerHTML = '<input type="checkbox" name="greek-' + noTexts + '" id="greek-' + noTexts+ '">';
Mocht je compatibiliteit met oudere browsers willen hebben(insertRow en insertCell worden niet ondersteund in Chrome < 4, Safari < 4 en Opera Presto < 2.1) kan je het in een try/catch stoppen:
try {
if(var tbl = document.getElementById("texts"))
tbl += '<tr><td>'+noTexts+'. </td><td><input type="text" name="text-'+noTexts+'" id="text-'+noTexts+'" tabindex="'+noTexts+'"/></td><td><input type="checkbox" name="greek-'+noTexts+'" id="greek-'+noTexts+'"/></td></tr>';
}
catch(e)
{
var tbl = document.getElementById("texts");
// stop nieuwe rij in tabel
var newTR = tbl.insertRow(tbl.rows.length);
// stop 3 nieuwe cellen in de nieuwe rij
for(var arrTD = new Array(3), i = 0; i < arrTD.length; i++)
arrTD[i] = newTR.insertCell(newTR.cells.length);
// vul cellen in
arrTD[0].innerHTML = noTexts + '.';
arrTD[1].innerHTML = '<input type="text" name="text-' + noTexts + '" id="text-' + noTexts + '" tabindex="' + noTexts + '">';
arrTD[2].innerHTML = '<input type="checkbox" name="greek-' + noTexts + '" id="greek-' + noTexts+ '"/>';
}
try { if(var tbl = document.getElementById("texts")) tbl += '<tr><td>'+noTexts+'. </td><td><input type="text" name="text-'+noTexts+'" id="text-'+noTexts+'" tabindex="'+noTexts+'"/></td><td><input type="checkbox" name="greek-'+noTexts+'" id="greek-'+noTexts+'"/></td></tr>'; } catch(e) { var tbl = document.getElementById("texts"); // stop nieuwe rij in tabel var newTR = tbl.insertRow(tbl.rows.length); // stop 3 nieuwe cellen in de nieuwe rij for(var arrTD = new Array(3), i = 0; i < arrTD.length; i++) arrTD[i] = newTR.insertCell(newTR.cells.length); // vul cellen in arrTD[0].innerHTML = noTexts + '.'; arrTD[1].innerHTML = '<input type="text" name="text-' + noTexts + '" id="text-' + noTexts + '" tabindex="' + noTexts + '">'; arrTD[2].innerHTML = '<input type="checkbox" name="greek-' + noTexts + '" id="greek-' + noTexts+ '"/>'; }
Deze code probeert eerst via de innerHTML property de nieuwe rij toe te voegen. Als dit een fout veroorzaakt(in IE dus) wordt de catch uitgevoerd. |