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

How to create HIDDEN Input element using DOM

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

Jul 20 '05 #1
1 32135
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
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
8
by: Matt Herson | last post by:
I have been trying to find a way to use JavaScript to change the value of a hidden field on submit. I am already invoking a JavaScript to handle the validation on submit. The reason I need to...
7
by: Eduard Dewolf | last post by:
Hi, Im have been changing my site to make it HTML 4.01 compliant As I should, I wrapped all INPUT tags in blocks I wrapped the not visible INPUT type HIDDEN tags in first PRE, later H6 tags...
0
by: yurps | last post by:
Hello here is my html, if you click the missing image in the first column on the left, the div is shown, when clicked again the div disappears...but the bottom border disappears as well...Is there...
6
by: Omar | last post by:
Hi, In a JSP I have the next: .... codigo = "<select name='" + nombre + "'>\n<option selected value='default'>Escoge</option><option value='todos'>Todos</option>"; if (miRS != null) while...
10
by: Mark McLellan | last post by:
Dear all Following the oft-repeated advice here and ciwas I have made my site nearly 4.01 strict (working on it). There are some items on which I would appreciate your advice: 1. Hidden...
13
by: Geoff Cox | last post by:
Hello, How do I create a form without using document.write() which opens a new window? I imagine it has to do with using a <SPAN ID='idvalue' etc element and...
2
by: Bill Steele | last post by:
I want to have a window pop up with a form. When the form is submitted, it needs to pass along the URL of the original window. If find on th web eight gazillion descriptions of how to pass data...
5
by: bucchi | last post by:
Hi, I am doing the following in a javascript function: var hiddenElement = document.createElement("input"); hiddenElement .setAttribute("type", "hidden"); hiddenElement...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.