I am trying to create a row in a table. In that row i have some input and select elements.
I want to add an onchange event to an select element.
I am trying to do so.. but not working (see the bolded code below)
Please help me.
// this addrowt() triggered when a button is clicked.
function addRowt()
{
var table1 = document.getElementById('slist');
var lastRow = table1.rows.length;
var iteration = lastRow;
var row = table1.insertRow(lastRow);
// Song number
var c1 = row.insertCell(0);
var it='song' + iteration;
var textNode = document.createTextNode(it);
c1.appendChild(textNode);
// song title
var c2 = row.insertCell(1);
var e2 = document.createElement('input');
e2.type = 'text';
e2.name = 'song_t' + iteration;
e2.id+
'song_t' + iteration;
e2.size = 25;
c2.appendChild(e2);
// song title
// cell creation
var c3 = row.insertCell(2);
//select 1
* var e3s1 = document.createElement('select');
e3s1.name = 'song_dt' + iteration + '1';
e3s1.id = 'song_dt' + iteration + '1';
e3s1.options[0] = new Option('MU 128kbps', 'MU 128kbps', true);
e3s1.options[1] = new Option('SS 128kbps', 'SS 128kbps');
e3s1.options[2] = new Option('MF 128kbps', 'MF 128kbps');
e3s1.options[3] = new Option('RS 128kbps', 'RS 128kbps');
e3s1.options[4] = new Option('--NA--', '');
e3s1.options[5] = new Option('Other', 'Other');
[B] // Here not working
e3s1.onselect = function() { checkother(); };[/B]
// I DEFINED THE checkother(); function
c3.appendChild(e3s1);
window.alert("hai");
// input for select 1
var e3is1 = document.createElement('input');
e3is1.type = 'text';
e3is1.name = 'song_dtt' + iteration + '1';
e3is1.id = 'song_dtt' + iteration + '1';
e3is1.size = 20;
e3is1.style.display='none';
c3.appendChild(e3is1);
// input 1
var e3i1 = document.createElement('input');
e3i1.type = 'text';
e3i1.name = 'song_dl' + iteration + '1';
e3i1.id = 'song_dl' + iteration + '1';
e3i1.size = 25;
c3.appendChild(e3i1);
c3.innerHTML += "<br>";
//select 2
var e3s2 = document.createElement('select');
e3s2.name = 'song_dt' + iteration + '2';
e3s2.id = 'song_dt' + iteration + '2';
e3s2.options[0] = new Option('MU 128kbps', 'MU 128kbps');
e3s2.options[1] = new Option('SS 128kbps', 'SS 128kbps', true);
e3s2.options[2] = new Option('MF 128kbps', 'MF 128kbps');
e3s2.options[3] = new Option('RS 128kbps', 'RS 128kbps');
e3s2.options[4] = new Option('--NA--', '');
e3s2.options[5] = new Option('Other', 'Other');
c3.appendChild(e3s2);
// input 2
var e3i2 = document.createElement('input');
e3i2.type = 'text';
e3i2.name = 'song_dl' + iteration + '2';
e3i2.id = 'song_dl' + iteration + '2';
e3i2.size = 25;
c3.appendChild(e3i2);
c3.innerHTML += "<br>";
//select 3
var e3s3 = document.createElement('select');
e3s3.name = 'song_dt' + iteration + '3';
e3s3.id = 'song_dt' + iteration + '3';
e3s3.options[0] = new Option('MU 128kbps', 'MU 128kbps' );
e3s3.options[1] = new Option('SS 128kbps', 'SS 128kbps' );
e3s3.options[2] = new Option('MF 128kbps', 'MF 128kbps', true);
e3s3.options[3] = new Option('RS 128kbps', 'RS 128kbps' );
e3s3.options[4] = new Option('--NA--', '' );
e3s3.options[5] = new Option('Other', 'Other' );
c3.appendChild(e3s3);
// input 3
var e3i3 = document.createElement('input');
e3i3.type = 'text';
e3i3.name = 'song_dl' + iteration + '3';
e3i3.id = 'song_dl' + iteration + '3';
e3i3.size = 25;
c3.appendChild(e3i3);
c3.innerHTML += "<br>";
//select 4
var e3s4 = document.createElement('select');
e3s4.name = 'song_dt' + iteration + '4';
e3s4.id = 'song_dt' + iteration + '4';
e3s4.options[0] = new Option('MU 128kbps', 'MU 128kbps');
e3s4.options[1] = new Option('SS 128kbps', 'SS 128kbps');
e3s4.options[2] = new Option('MF 128kbps', 'MF 128kbps');
e3s4.options[3] = new Option('RS 128kbps', 'RS 128kbps', true);
e3s4.options[4] = new Option('--NA--', '');
e3s4.options[5] = new Option('Other', 'Other');
c3.appendChild(e3s4);
// input 4
var e3i4 = document.createElement('input');
e3i4.type = 'text';
e3i4.name = 'song_dl' + iteration + '4';
e3i4.id = 'song_dl' + iteration + '4';
e3i4.size = 25;
c3.appendChild(e3i4);
// lyrics by
var c4 = row.insertCell(3);
var e4 = document.createElement('input');
e4.type = 'text';
e4.name = 'song_lr' + iteration;
e4.id = 'song_lr' + iteration;
e4.size = 25;
c4.appendChild(e4);
// singer
var c5 = row.insertCell(4);
var e5 = document.createElement('input');
e5.type = 'text';
e5.name = 'song_sr' + iteration;
e5.id = 'song_sr' + iteration;
e5.size = 25;
c5.appendChild(e5);
e2.focus();
var slno1 = document.getElementById('slno');
slno1.value = parseInt(slno1.value) + 1;
}