473,396 Members | 2,113 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,396 software developers and data experts.

Javascript Problem in Firefox

Dear Members,

I am going to create the online form creation in html with javascript, i have a problem with the following code, i got this code from internet, the following script only works in IE but it doesn't work in other browser like (Firefox and Opera), i don't know what's the problem with code. If anybody know the solution let me know...



Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>Adding and Removing Rows</title>
  4.         <script language="javascript">
  5.  
  6.             //add a new row to the table
  7.             function addRow()
  8.             {
  9.                 //add a row to the rows collection and get a reference to the newly added row
  10.                 var newRow = document.all("tblGrid").insertRow();
  11.  
  12.                 //add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes
  13.  
  14.                 var oCell = newRow.insertCell();
  15.                 oCell.innerHTML = "<input type='text' name='t1'>";
  16.  
  17.                 oCell = newRow.insertCell();
  18.                 oCell.innerHTML = "<input type='text' name='t2'>";
  19.  
  20.                 oCell = newRow.insertCell();
  21.                 oCell.innerHTML = "<input type='text' name='t3'> &nbsp;&nbsp;<input type='button' value='Delete' onclick='removeRow(this);'/>";            
  22.             }
  23.  
  24.             //deletes the specified row from the table
  25.             function removeRow(src)
  26.             {
  27.                 /* src refers to the input button that was clicked.    
  28.                    to get a reference to the containing <tr> element,
  29.                    get the parent of the parent (in this case case <tr>)
  30.                 */            
  31.                 var oRow = src.parentElement.parentElement;        
  32.  
  33.                 //once the row reference is obtained, delete it passing in its rowIndex            
  34.                 document.all("tblGrid").deleteRow(oRow.rowIndex);        
  35.             }
  36.  
  37.         </script>
  38.     </head>
  39.     <body>
  40.  
  41.         <!-- sample table grid with 3 columns and 4 rows that are presented by default -->
  42.         <table id="tblGrid" style="table-layout:fixed">
  43.             <tr>
  44.                 <td width="150px">Field1</td>
  45.                 <td width="150px">Field2</td>
  46.  
  47.                 <td width="250px">Field3</td>
  48.             </tr>
  49.             <tr>
  50.                 <td><input type="text" name="t1" /></td>
  51.                 <td><input type="text" name="t2" /></td>
  52.                 <td><input type="text" name="t3" /> &nbsp;&nbsp;<input type="button" value="Delete" onclick="removeRow(this);" /></td>
  53.             </tr>
  54.             <tr>
  55.  
  56.                 <td><input type="text" name="t1" /></td>
  57.                 <td><input type="text" name="t2" /></td>
  58.                 <td><input type="text" name="t3" /> &nbsp;&nbsp;<input type="button" value="Delete" onclick="removeRow(this);" /></td>
  59.             </tr>
  60.             <tr>
  61.                 <td><input type="text" name="t1" /></td>
  62.                 <td><input type="text" name="t2" /></td>
  63.                 <td><input type="text" name="t3" /> &nbsp;&nbsp;<input type="button" value="Delete" onclick="removeRow(this);" /></td>
  64.  
  65.             </tr>
  66.             <tr>
  67.                 <td><input type="text" name="t1" /></td>
  68.                 <td><input type="text" name="t2" /></td>
  69.                 <td><input type="text" name="t3" /> &nbsp;&nbsp;<input type="button" value="Delete" onclick="removeRow(this);" /></td>
  70.             </tr>
  71.         </table>
  72.         <hr>
  73.  
  74.         <input type="button" value="Add Row" onclick="addRow();" />
  75.         <hr>
  76.  
  77.     </body>
  78.  
  79.  
  80. </html>


Thanks in Advance,



V. Prasath
Apr 6 '09 #1
2 1858
dmjpro
2,476 2GB
"document.all" does not work in Mozilla.
Always try yo follow the W3C specification for JavaScript.
That would be working in all browsers ;)
Apr 6 '09 #2
acoder
16,027 Expert Mod 8TB
In case you're wondering what the standard method is, it's document.getElementById() with a valid ID.
Apr 6 '09 #3

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

Similar topics

12
by: Howard Kaikow | last post by:
Yesterday, I decided to try Firefox. I've encountered a behavior that is either a bug in Firefox or a bug in my Javascript code. I'll try to explain the problem, hoping that this newsgroup can...
5
by: LRW | last post by:
(Sorry if this is a repost...my newsreader keeps crashing on the posting--I don't know if the message going out or not) For some reason this javascript just won't work in Firefox. It works fine...
13
by: John Smith | last post by:
I am using IE 6.0 from http://www.javaworld.com/javaworld/jw-07-1996/jw-07-javascript-p2.html I gather that "If you need to test a number of command lines, you can reduce the keystrokes by...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
4
by: lmarceglia | last post by:
Hi, I have this website that doesn't work in Firefox 1.5: www.pianetaluca.com The HTML source is: <TITLE>PianetaLuca</TITLE> </HEAD>
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
11
by: minnesotti | last post by:
Hi there, I subscribed to a photographic pictures-hosting website which is heavy on JavaScript. My preferred latest browser Mozilla Firefox does not work with it -- no pictures are displayed and...
8
by: Matt Kruse | last post by:
http://news.zdnet.com/2100-1009_22-6121608.html Hackers claim zero-day flaw in Firefox 09 / 30 / 06 | By Joris Evers SAN DIEGO--The open-source Firefox Web browser is critically flawed in...
16
by: Eric | last post by:
I have a user of a web application written in Java/JSP that is unable to login to the site simply because certain links on the page do not run when they are clicked. Other popups using Javascript...
12
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.