473,396 Members | 2,038 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.

appendChild to FORM element

I'm trying to append a form element to a form like so:

var frm = document.createElement("FORM");
frm.method = "post";
frm.action = "include/writeData.asp";

var ff, values = [field, val, course, txt];

for (var i=0; i<values.length; i++) {
ff = document.createElement("INPUT");
ff.type = "hidden";
ff.name = "field"+i;
ff.id = "field"+i;
ff.value = values[i];
frm.appendChild(ff);
}
....

It seems to work fine in FF but IE fails silently. Is there a way to
dynamically add form elements to a form in IE (or have I made some other
mistake)?
Andrew Poulos
Jul 23 '05 #1
6 16485
VK
> I'm trying to append a form element to a form
It seems to work fine in FF but IE fails silently.


....
ff.value = values[i];
frm.appendChild(ff);
if (frm.normalize) {frm.normalize();}
....

The last statement will re-validate form elements in the collection.

Jul 23 '05 #2
VK wrote:
I'm trying to append a form element to a form
It seems to work fine in FF but IE fails silently.

...
ff.value = values[i];
frm.appendChild(ff);
if (frm.normalize) {frm.normalize();}
...

The last statement will re-validate form elements in the collection.

Thanks but it made no difference.

If I put an alert immediately before and another immediately after the
appendChild call he first alert displays but not the second!

Andrew Poulos
Jul 23 '05 #3
VK


Andrew Poulos wrote:
VK wrote:
I'm trying to append a form element to a form
It seems to work fine in FF but IE fails silently.

...
ff.value = values[i];
frm.appendChild(ff);
if (frm.normalize) {frm.normalize();}
...

The last statement will re-validate form elements in the collection.

Thanks but it made no difference.

If I put an alert immediately before and another immediately after the
appendChild call he first alert displays but not the second!

Andrew Poulos

Sorry, and who will add the form itself? :-)
And you have to do it *only* after onload when the DOM structure is
fully rendered, otherwise appendChild's will not find any parents.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function test() {
var frm = document.createElement("FORM");
frm.method = "post";
frm.action = "include/writeData.asp";
var ff, values = ["foo", "bar", "qwerty", "eggog"];
for (var i=0; i<values.length; i++) {
ff = document.createElement("INPUT");
ff.type = "text";
ff.name = "field"+i;
ff.id = "field"+i;
ff.value = values[i];
frm.appendChild(ff);
}
document.body.appendChild(frm);
frm.normalize();
}
window.onload = test;
</script>
</head>

<body bgcolor="#FFFFFF">
</body>
</html>

Jul 23 '05 #4
ASM
VK wrote:
And you have to do it *only* after onload when the DOM structure is
fully rendered, otherwise appendChild's will not find any parents.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function test() {
var frm = document.createElement("FORM");
frm.method = "post";
frm.action = "include/writeData.asp";
var ff, values = ["foo", "bar", "qwerty", "eggog"];
for (var i=0; i<values.length; i++) {
ff = document.createElement("INPUT");
ff.type = "text";
here, my IE 5.2 (Mac) cries :
"cet objet ne prend pas en charge cette propriete ou methode"
'this object doesnt accept this propriety or method'
ff.name = "field"+i;
ff.id = "field"+i;
ff.value = values[i];
frm.appendChild(ff);
}
document.body.appendChild(frm);
frm.normalize();
}
window.onload = test;
</script>
</head>

<body bgcolor="#FFFFFF">
</body>
</html>

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #5
VK
ASM wrote:
here, my IE 5.2 (Mac) cries :
"cet objet ne prend pas en charge cette propriete ou methode"
'this object doesnt accept this propriety or method'
ff.name = "field"+i;
ff.id = "field"+i;
ff.value = values[i];
frm.appendChild(ff);
}
document.body.appendChild(frm);
frm.normalize();
}
window.onload = test;
</script>
</head>

<body bgcolor="#FFFFFF">
</body>
</html>

Rien de fair, Monsieur!

Pour le moment utilisez votre Opera et attendez jusqu'a ce que Safari
deviendrait un Homme.

:-)

Also you may try to change:
frm.normalize();
to
if (frm.normalize) {frm.normalize();}

Maybe this method was not implemented yet in EI 5.0
Because overall it already support DOM methods.

Jul 23 '05 #6
ASM
VK wrote:
ASM wrote:
here, my IE 5.2 (Mac) cries :
"cet objet ne prend pas en charge cette propriete ou methode"
'this object doesnt accept this propriety or method'

<couic>
Rien de fair, Monsieur!
Moi non plus tres cher :-)
Anyway I hate IE
Pour le moment utilisez votre Opera et attendez jusqu'a ce que Safari
deviendrait un Homme.
They have well grown and the script works fine in :
Opera, Safari, iCab 3.0, FF 1.0.4 ... except IE :-( as I said
thank you
:-)

Also you may try to change:
frm.normalize();
to
if (frm.normalize) {frm.normalize();}


Do not think that stops IE
but this :
ff.type = "text";

I think there is a bug in types of inputs with my IE5.2-Mac
if I comment this line -> all rest works correctly
(curiously the inputs look like text fields)

and normalize() doesn't disturb IE

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #7

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

Similar topics

2
by: Paul | last post by:
I am trying to get a form to dynamicaly add hidden elements. Below is the function I've created, basicaly it loops thru an array and attempts to add those values to a newly created hidden input...
1
by: Don Stefani | last post by:
Hello, I have a form that I want to submit "onchange", OK I've got that working, but when the form submits, I want to pass along a value to a CGI script, as if that value was in a hidden form...
3
by: michael | last post by:
let me keep it clean, quick and simple. I am passing a variable into another window and am reassigning the value on the new page - window.document...value = opener.document. ....value and...
15
by: Christoph | last post by:
I'm trying to make it so that if the user sets focus to a form element (text), it automatically sets focus to the very next form element. This will, in effect, prevent the user from modifying the...
14
by: kelvin.jones | last post by:
Hi, if I had the ID of an input element, how can I find the input's FORM in javascript? Basically, given a input's dom id, I want to insert something in the onSubmit of the Form that that input...
12
by: Eric Layman | last post by:
Hi, What's the difference between a normal web element: <input type="text" id="txtname" name="txtname" runat="server"> vs webcontrol text box: <asp:Textbox id="username" Columns="10"...
4
by: rn5a | last post by:
I am storing the physical path of images, along with 3 more columns, in a MS-Access DB table. I want to provide users the option to change this physical image path (as well as the records in the...
1
by: will1 | last post by:
Hi, I have searched for several days to try to resolve my little problem.Sorry but I have very little experience with JavaScript OOP. I have a form which consists of at least one line. Each...
4
by: damicomj | last post by:
I am trying to pass an HTML Form variable to a .JS file. The .JS file then passes the variable to an ASP page, which works properly. The part that doesn't work properly is trying to pass it to the...
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.