473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need Help!!! Javascript DOM

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!!!

Expand|Select|Wrap|Line Numbers
  1. function addRow()
  2. {
  3.   var tbl=document.getElementById('game');
  4.   var lastRow = tbl.rows.length;
  5.   var row = tbl.insertRow(lastRow);
  6.  
  7.   var cell_1 = row.insertCell(0);
  8.   var cell_2= row.insertCell(1);
  9.   var cell_3 = row.insertCell(2);
  10.   var cell_4 = row.insertCell(3);
  11.  
  12.  
  13. cell_1.innerHTML='<div align="center"><input type="button" onclick="deleteRow(this)" value="Delete" ></div>';
  14.  
  15. var team_1 = document.createElement("select");  
  16.  
  17. team_1.setAttribute('name','team_A');
  18.  
  19. alert(team_1.name);
  20. team_1.options[0] = new Option("Ballina",1);
  21. team_1.options[1] = new Option("Silvermines",2);
  22. team_1.options[2] = new Option("Kilruane",3);
  23. team_1.options[3] = new Option("Nenagh",4);
  24. team_1.options[4] = new Option("Borrisakane",5);
  25. team_1.options[5] = new Option("Potroe",6);
  26. team_1.options[6] = new Option("Burgess",7);
  27. team_1.options[7] = new Option("Kiladangan",8);
  28. team_1.options[8] = new Option("Lorrah",9);
  29. team_1.options[9] = new Option("Roscrea",10);
  30. team_1.options[10] = new Option("TempleDerry",11);
  31. team_1.options[11] = new Option("Shannon Rovers",12);
  32.  
  33. cell_2.appendChild(team_1);
  34.  
  35.  
  36.  
  37. var team_2 = document.createElement('select');  
  38.  
  39.  
  40. team_2.name = 'team_B';
  41.  
  42.  
  43.  
  44. team_2.options[0] = new Option("Ballina",1);
  45. team_2.options[1] = new Option("Silvermines",2);
  46. team_2.options[2] = new Option("Kilruane",3);
  47. team_2.options[3] = new Option("Nenagh",4);
  48. team_2.options[4] = new Option("Borrisakane",5);
  49. team_2.options[5] = new Option("Potroe",6);
  50. team_2.options[6] = new Option("Burgess",7);
  51. team_2.options[7] = new Option("Kiladangan",8);
  52. team_2.options[8] = new Option("Lorrah",9);
  53. team_2.options[9] = new Option("Roscrea",10);
  54. team_2.options[10] = new Option("TempleDerrteam_2",11);
  55. team_2.options[11] = new Option("Shannon Rovers",12);
  56.  
  57. cell_3.appendChild(team_2);
  58.  
  59.  
  60.  
  61. var mydate= new Date()
  62. var theyear=mydate.getFullYear()
  63. var themonth=mydate.getMonth()+1
  64. var thetoday=mydate.getDate()
  65.  
  66. var dateinput = document.createElement("input");
  67. dateinput.type = 'text';
  68. dateinput.id = 'no'+lastRow;
  69. dateinput.value=thetoday+'-'+themonth+'-'+theyear;
  70. dateinput.size='25';
  71. cell_4.appendChild(dateinput);
  72.  
  73. var getdate = document.createElement('a');
  74. getdate.href= "javascript:NewCal('no"+lastRow+"','ddmmyyyy')";
  75. getdate.innerHTML= "<img src='../../calender/cal.gif' width='16' height='16' border='0' alt='Pick a date'>";
  76. cell_4.appendChild(getdate);
  77.  
  78. }
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
Jul 19 '07 #1
5 1664
gits
5,390 Expert Mod 4TB
hi ...

are you using IE? IE don't let you set the name of a form-element properly. have a look at:

http://javascript.about.com/library/bliebug2.htm

other browsers do well ... only the ie-jscript makes a problem here.

kind regards
Jul 20 '07 #2
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.
Jul 20 '07 #3
iam_clint
1,208 Expert 1GB
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
Jul 20 '07 #4
Thanks for your help. I will ask more questions as I progress through my project.
Jul 22 '07 #5
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
Jul 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
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>
19
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...
5
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,...
4
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...
9
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();
1
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)...
2
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...
22
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.