Raghuram Banda wrote:
Hi All,
Can any one help me how to create a HIDDEN element using JavaScript
(DOM) dynamically
The following codes works fine with IE but not in Netscape
currentElement = document.createElement("input");
currentElement.setAttribute("type", "hidden");
currentElement.setAttribute("name", "hiddenName");
currentElement.setAttribute("id", "hiddenName");
currentElement.setAttribute("value", "14041978");
currentCell.appendChild(currentElement);
and I'm appending 'currentCell' to a table cell which was also created
dynamically.
Can any one pull me out of this problem
Thanks in advance
Raghuram Banda
The reference to "currentCell" probably isn't what you think it is, since
Gecko-based browsers include whitespace as text nodes in the DOM,
something like:
<tr id="myRow">
<td></td>
Could be accessed by document.getElementById('myRow').firstChild in IE,
but in a Gecko-based browser (Mozilla, Safari, Firebird), all you'd get is
the new line text node which follows the <tr>.
Also, to prevent possible problems appending an input to a cell, and since
the thing you're adding is just a hidden input anyway, why not just append
it to either the body, or the form?
<body>
<form name="myForm">
....
document.body.appendChild(currentElement);
.... or ...
document.forms['myForm'].appendChild(currentElement);
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html