Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP : this javascript script do not work in firefox but work in ie

Status
Not open for further replies.

JJJ777

Programmer
Jun 5, 2002
33
0
0
MY
hi all....

i'm working on form that allow user to add new row in a table..i use javascript below...it works in IE but fail in
firefox.....hope u all cal help me please...?
tq in advance.



<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function addRow(id){
var tbody = document.getElementById
(id).getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")
var td1 = document.createElement("TD")
td1.appendChild(document.createTextNode("column 1"))
var td2 = document.createElement("TD")
td2.appendChild (document.createTextNode("column 2"))
row.appendChild(td1);
row.appendChild(td2);
tbody.appendChild(row);
}
// End -->
</script>


<BODY>

<a href="javascript:addRow('myTable')">Add row</a>

<table id="myTable" cellspacing="0" border="1">
<tbody>
<tr>
<td>row1_column1</td><td>row1_column1</td>
</tr>
</tbody>



 
I don't think getElementsByTagName is supported in FireFox.
 

getElementsByTagName is supported in Firefox, AFAIK, as it is a standard DOM method.

Although the code you've given above is hardly well-formed (no html or head tags, and no closing body or table tags), it works fine for me in FF.

Have you tried looking in the JS console to see what errors you are getting?

Failing that, tidy your code up and see what happens.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
hi ..tq for replying....

yes this code actually work in fireforx tq guys..
typo in "t" in <tbody>...at my actual code..

it will not work when we put it like this:

td1.appendChild(document.createTextNode("<input name=\"start_date1\" type=\"text\" size=\"7\" >"))

because of the property...

 

If you want to create a new HTML element, you cannot do it using createTextNode. The method name should have given that away.

Use createElement instead (as you are already using this, I'm not entirely sure why you didn't try this yourself)... again, the method name gives it away a bit.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top