473,394 Members | 1,852 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,394 software developers and data experts.

Validate document.createElement

I have a page which uses JavaScript to create form elements using
document.createElement('input'), etc.. Both Firefox and IE have no
problem accomplishing this and when the form is submitted all the
information is passed correctly.

I am now trying to validate the form using JavaScript when the page is
submitted. Firefox has no problems with this but IE returns
'document.form1.*THE FORM FIELD*.value is null or not an object' for
the elements that were created using document.createElement when I try
get their value using 'document.form1.*THE FORM FIELD*.value'. How do
I get the value of the form elements that were created using
JavaSCript?

(BTW: The form name is form1).
Jul 23 '05 #1
2 2640
Dave wrote:
[...]

I am now trying to validate the form using JavaScript when the page is
submitted. Firefox has no problems with this but IE returns
'document.form1.*THE FORM FIELD*.value is null or not an object' for
the elements that were created using document.createElement when I try
get their value using 'document.form1.*THE FORM FIELD*.value'. How do
I get the value of the form elements that were created using
JavaSCript?


Without seeing a bit of code, how can we tell? Just post a minimal,
concise example that demonstrates your problem or provide a URL to
same.

Say a bit that creates an element gives it appropriate attributes and
adds it to the document, and another bit that tries to read its value
or text or whatever.

At a guess, I'd say the issue is with the way you are creating the
attribute you are using to reference the form element - check the id
and/or name you are assigning it.

Fred.
Jul 23 '05 #2


Dave wrote:
I have a page which uses JavaScript to create form elements using
document.createElement('input'), etc.. Both Firefox and IE have no
problem accomplishing this and when the form is submitted all the
information is passed correctly.

I am now trying to validate the form using JavaScript when the page is
submitted. Firefox has no problems with this but IE returns
'document.form1.*THE FORM FIELD*.value is null or not an object' for
the elements that were created using document.createElement when I try
get their value using 'document.form1.*THE FORM FIELD*.value'. How do
I get the value of the form elements that were created using
JavaSCript?


That is a known problem with IE (on Win at least). What kind of input
control is that? If it is a text or password or select or textarea where
you usually use a unique name you can help yourself by also setting the
id of that element e.g.

var input = document.createElement('input');
input.type = 'text';
input.id = 'inputName';
input.name = 'inputName';
document.forms[0].appendChild(input);

then the element is accessible as

document.forms[0].inputName

or as

document.forms[0].elements.inputName

That approach fails of course if you want to create a group of radio
buttons which need to have the same name but are not allowed to have the
same id but event then you can help yourself by using an id attribute,
just make sure you assign different ids to the different radio buttons
and then access elements as
document.forms[0].elements.radioButtonId

If you are desperate you can also use the IE only approach
var input =
document.createElement('<input type="radio" name="radioName" value="Kibo">')
that way IE manages to update the form.elements collection properly.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

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

Similar topics

1
by: QuantDev | last post by:
Hi NG, I would need to validate an XML fragment against a type defined within an XSD (which defines many other things). What is the correct way of achieving this? QD2004
4
by: Dante | last post by:
Hello. I have a Javascript that gets data from an XML document and displays it through javascript. The problem is that when I do dcfile.getElementsByTagName("subhead").firstChild.nodeName all I...
1
by: Weston C | last post by:
After noticing some problems with a script, I tried testing various bits in the squarefree javascript shell ( http://www.squarefree.com/shell/shell.html ) and noticed this: var anchor =...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
10
by: andreister | last post by:
He there! I've discovered that the ================================================= document.links('link_id_here').href = "something"; ================================================= is...
3
by: ezmiller | last post by:
So I have some code that gets the body element of another frame and then tries to dynamically write a table. The code fails when, after creating the table, I try to append it to the document. I...
2
by: Gordowey | last post by:
Hi all,...I have an special situation, that I can not solve.... I need some help This is my scenario: 1.- I have n-combos (showing available rooms from an hotel) in my web-page. The number of...
1
by: anilareddy | last post by:
I have an application like this. I need to validate the start time in 2nd row against the start row in first row. I mean The start time value entered in the second row must not b the value entered in...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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
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...

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.