Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Validate document.createElement

Reply
Thread Tools

Validate document.createElement

 
 
Dave
Guest
Posts: n/a
 
      11-05-2004
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).


 
Reply With Quote
 
 
 
 
Fred Oz
Guest
Posts: n/a
 
      11-05-2004
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.
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-05-2004


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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie, unable to validate with genuine windows XP Pro? =?Utf-8?B?SWdvciBRdWFzaW1vZG8=?= Microsoft Certification 0 11-05-2005 08:17 PM
Validate SessionID Shankar Reddy ASP .Net 3 09-25-2004 05:59 AM
can i validate the presence of .Net framework in the OS a_srivathsan ASP .Net 2 09-08-2004 03:56 AM
Re: How could I validate a MCSE certificate? Andy Foster MCSE 0 07-02-2003 03:03 PM
Re: How could I validate a MCSE certificate? Dandy WEYN MCSE 0 07-02-2003 11:35 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57