I am currently learning javascript and DOM. Basically I am currently writing a function to add rows to a table and I am trying to do it using DOM. Each row is made up of 4 cells. Here is the code!!!
[CODE=javascript]function addRow()
{
var tbl=document.ge tElementById('g ame');
var lastRow = tbl.rows.length ;
var row = tbl.insertRow(l astRow);
var cell_1 = row.insertCell( 0);
var cell_2= row.insertCell( 1);
var cell_3 = row.insertCell( 2);
var cell_4 = row.insertCell( 3);
cell_1.innerHTM L='<div align="center"> <input type="button" onclick="delete Row(this)" value="Delete" ></div>';
var team_1 = document.create Element("select ");
team_1.setAttri bute('name','te am_A');
alert(team_1.na me);
team_1.options[0] = new Option("Ballina ",1);
team_1.options[1] = new Option("Silverm ines",2);
team_1.options[2] = new Option("Kilruan e",3);
team_1.options[3] = new Option("Nenagh" ,4);
team_1.options[4] = new Option("Borrisa kane",5);
team_1.options[5] = new Option("Potroe" ,6);
team_1.options[6] = new Option("Burgess ",7);
team_1.options[7] = new Option("Kiladan gan",8);
team_1.options[8] = new Option("Lorrah" ,9);
team_1.options[9] = new Option("Roscrea ",10);
team_1.options[10] = new Option("TempleD erry",11);
team_1.options[11] = new Option("Shannon Rovers",12);
cell_2.appendCh ild(team_1);
var team_2 = document.create Element('select ');
team_2.name = 'team_B';
team_2.options[0] = new Option("Ballina ",1);
team_2.options[1] = new Option("Silverm ines",2);
team_2.options[2] = new Option("Kilruan e",3);
team_2.options[3] = new Option("Nenagh" ,4);
team_2.options[4] = new Option("Borrisa kane",5);
team_2.options[5] = new Option("Potroe" ,6);
team_2.options[6] = new Option("Burgess ",7);
team_2.options[7] = new Option("Kiladan gan",8);
team_2.options[8] = new Option("Lorrah" ,9);
team_2.options[9] = new Option("Roscrea ",10);
team_2.options[10] = new Option("TempleD errteam_2",11);
team_2.options[11] = new Option("Shannon Rovers",12);
cell_3.appendCh ild(team_2);
var mydate= new Date()
var theyear=mydate. getFullYear()
var themonth=mydate .getMonth()+1
var thetoday=mydate .getDate()
var dateinput = document.create Element("input" );
dateinput.type = 'text';
dateinput.id = 'no'+lastRow;
dateinput.value =thetoday+'-'+themonth+'-'+theyear;
dateinput.size= '25';
cell_4.appendCh ild(dateinput);
var getdate = document.create Element('a');
getdate.href= "javascript:New Cal('no"+lastRo w+"','ddmmyyyy' )";
getdate.innerHT ML= "<img src='../../calender/cal.gif' width='16' height='16' border='0' alt='Pick a date'>";
cell_4.appendCh ild(getdate);
}[/CODE]
The CODE is not entirely finished but my problem is when I try to access the select list "team_A" either through getElementsByNa me or "team_B" . It cant find it. Can anyone tell me where I am going wrong. Thanks
[CODE=javascript]function addRow()
{
var tbl=document.ge tElementById('g ame');
var lastRow = tbl.rows.length ;
var row = tbl.insertRow(l astRow);
var cell_1 = row.insertCell( 0);
var cell_2= row.insertCell( 1);
var cell_3 = row.insertCell( 2);
var cell_4 = row.insertCell( 3);
cell_1.innerHTM L='<div align="center"> <input type="button" onclick="delete Row(this)" value="Delete" ></div>';
var team_1 = document.create Element("select ");
team_1.setAttri bute('name','te am_A');
alert(team_1.na me);
team_1.options[0] = new Option("Ballina ",1);
team_1.options[1] = new Option("Silverm ines",2);
team_1.options[2] = new Option("Kilruan e",3);
team_1.options[3] = new Option("Nenagh" ,4);
team_1.options[4] = new Option("Borrisa kane",5);
team_1.options[5] = new Option("Potroe" ,6);
team_1.options[6] = new Option("Burgess ",7);
team_1.options[7] = new Option("Kiladan gan",8);
team_1.options[8] = new Option("Lorrah" ,9);
team_1.options[9] = new Option("Roscrea ",10);
team_1.options[10] = new Option("TempleD erry",11);
team_1.options[11] = new Option("Shannon Rovers",12);
cell_2.appendCh ild(team_1);
var team_2 = document.create Element('select ');
team_2.name = 'team_B';
team_2.options[0] = new Option("Ballina ",1);
team_2.options[1] = new Option("Silverm ines",2);
team_2.options[2] = new Option("Kilruan e",3);
team_2.options[3] = new Option("Nenagh" ,4);
team_2.options[4] = new Option("Borrisa kane",5);
team_2.options[5] = new Option("Potroe" ,6);
team_2.options[6] = new Option("Burgess ",7);
team_2.options[7] = new Option("Kiladan gan",8);
team_2.options[8] = new Option("Lorrah" ,9);
team_2.options[9] = new Option("Roscrea ",10);
team_2.options[10] = new Option("TempleD errteam_2",11);
team_2.options[11] = new Option("Shannon Rovers",12);
cell_3.appendCh ild(team_2);
var mydate= new Date()
var theyear=mydate. getFullYear()
var themonth=mydate .getMonth()+1
var thetoday=mydate .getDate()
var dateinput = document.create Element("input" );
dateinput.type = 'text';
dateinput.id = 'no'+lastRow;
dateinput.value =thetoday+'-'+themonth+'-'+theyear;
dateinput.size= '25';
cell_4.appendCh ild(dateinput);
var getdate = document.create Element('a');
getdate.href= "javascript:New Cal('no"+lastRo w+"','ddmmyyyy' )";
getdate.innerHT ML= "<img src='../../calender/cal.gif' width='16' height='16' border='0' alt='Pick a date'>";
cell_4.appendCh ild(getdate);
}[/CODE]
The CODE is not entirely finished but my problem is when I try to access the select list "team_A" either through getElementsByNa me or "team_B" . It cant find it. Can anyone tell me where I am going wrong. Thanks
Comment