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!!! - function addRow()
-
{
-
var tbl=document.getElementById('game');
-
var lastRow = tbl.rows.length;
-
var row = tbl.insertRow(lastRow);
-
-
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.innerHTML='<div align="center"><input type="button" onclick="deleteRow(this)" value="Delete" ></div>';
-
-
var team_1 = document.createElement("select");
-
-
team_1.setAttribute('name','team_A');
-
-
alert(team_1.name);
-
team_1.options[0] = new Option("Ballina",1);
-
team_1.options[1] = new Option("Silvermines",2);
-
team_1.options[2] = new Option("Kilruane",3);
-
team_1.options[3] = new Option("Nenagh",4);
-
team_1.options[4] = new Option("Borrisakane",5);
-
team_1.options[5] = new Option("Potroe",6);
-
team_1.options[6] = new Option("Burgess",7);
-
team_1.options[7] = new Option("Kiladangan",8);
-
team_1.options[8] = new Option("Lorrah",9);
-
team_1.options[9] = new Option("Roscrea",10);
-
team_1.options[10] = new Option("TempleDerry",11);
-
team_1.options[11] = new Option("Shannon Rovers",12);
-
-
cell_2.appendChild(team_1);
-
-
-
-
var team_2 = document.createElement('select');
-
-
-
team_2.name = 'team_B';
-
-
-
-
team_2.options[0] = new Option("Ballina",1);
-
team_2.options[1] = new Option("Silvermines",2);
-
team_2.options[2] = new Option("Kilruane",3);
-
team_2.options[3] = new Option("Nenagh",4);
-
team_2.options[4] = new Option("Borrisakane",5);
-
team_2.options[5] = new Option("Potroe",6);
-
team_2.options[6] = new Option("Burgess",7);
-
team_2.options[7] = new Option("Kiladangan",8);
-
team_2.options[8] = new Option("Lorrah",9);
-
team_2.options[9] = new Option("Roscrea",10);
-
team_2.options[10] = new Option("TempleDerrteam_2",11);
-
team_2.options[11] = new Option("Shannon Rovers",12);
-
-
cell_3.appendChild(team_2);
-
-
-
-
var mydate= new Date()
-
var theyear=mydate.getFullYear()
-
var themonth=mydate.getMonth()+1
-
var thetoday=mydate.getDate()
-
-
var dateinput = document.createElement("input");
-
dateinput.type = 'text';
-
dateinput.id = 'no'+lastRow;
-
dateinput.value=thetoday+'-'+themonth+'-'+theyear;
-
dateinput.size='25';
-
cell_4.appendChild(dateinput);
-
-
var getdate = document.createElement('a');
-
getdate.href= "javascript:NewCal('no"+lastRow+"','ddmmyyyy')";
-
getdate.innerHTML= "<img src='../../calender/cal.gif' width='16' height='16' border='0' alt='Pick a date'>";
-
cell_4.appendChild(getdate);
-
-
}
The CODE is not entirely finished but my problem is when I try to access the select list "team_A" either through getElementsByName or "team_B" . It cant find it. Can anyone tell me where I am going wrong. Thanks
5 1664
Thanks I tried
team_1 = document.createElement("<select name='team_A'></select>");
instead of
team_1 = document.createElement("select");
team_1.name = " team_A";
However at the end of the function just for testing purposes I used
alert(document.getElementsByName('team_A').name);
Just to see the result.
and the alert came up with te result undefined
Do you know where the problem is in this script.
Thanks.
thats because
document.getElementsByName('team_A').name
is plural so you gotta tell it which team_a to get
document.getElementsByName('team_A')[0].name
Thanks for your help. I will ask more questions as I progress through my project.
gits 5,390
Expert Mod 4TB
Thanks for your help. I will ask more questions as I progress through my project.
no problem ;) you and your questions are always welcome ... post back anytime ...
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lucy |
last post by:
help! javascript inline of an HTML to open an HTML in a target window.
Something like...
<html>
<head>
<title>test</title>
</head>
<body>
|
by: Fran?ois Laroche |
last post by:
hey guys, I know that you will tell me that's easier to do in php or
even in asp, but I just dont have the time to learn it
1- I need a javascript that will show the date of tomorrow
2- I need a...
|
by: TrvlOrm |
last post by:
HI There,
I have been struggling with JavaScript code for days now, and this is
my last resort! Please help...
I am trying to create a JavaScript slide show with links for Next
Slide,...
|
by: namemattersnot |
last post by:
Re,
SCENARIO: User clicks a link and a javascript function creates dynamic
content in <div id="content"></div> using:
document.getElementById("content").innerHTML = something
In the page's...
|
by: mistral |
last post by:
Need help to remove list of days from date script. Need format "June
07, 2006"
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
// Get today's current date.
var now = new Date();
|
by: pmarisole |
last post by:
I need help in calculating a score from a row of drop-down values.
I need to use the onChange to tally the score as the user moves across
9 categories (with drop-down selection of 1-9 or N/A)...
|
by: JayCally |
last post by:
I want to add the current weather conditions in my area to my site. I've looked at some of the sites that will give you a generated script to add to your site but I don't like the way they look. I...
|
by: canabatz |
last post by:
Hi all!
i got a countdown timer for auctions that runing.
i got a DIV that refreshs every 4 seconds
that DIV is refreshed by ajax ,the file that is refreshed is timer.php for example!!
my...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |