![]() |
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). |
Re: Validate document.createElement
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. |
Re: Validate document.createElement
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/ |
| All times are GMT. The time now is 09:22 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.