Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem accessing form elements created in javascript

Status
Not open for further replies.

alisonpurcell

Programmer
Mar 26, 2003
9
0
0
GB
Hi,
I'm really stumped with this one so I hope someone can help. I have a DHTML menu that creates some form elements, and this seems to work ok in that they can be read following a submit. However, they need modifying later in the javascript (before the submit) but I can't seem to access them. To test it I have the following code:

menuForm=document.getElementById('form1');

element=document.createElement('input');
element.name='mytest';
menuForm.appendChild(element);

if(menuForm.elements['mytest'])
{
alert("menuForm.elements['mytest'] exists");
}
else
{
alert("menuForm.elements[mytest] doesn't exist");
}


It shows as not existing even though I have just created it.

Any suggestions much appreciated.
 
Just a thought - havent tried this...
Have you tried using setAttribute and adding an id to the input tag? You could then try document.getElementById("id") in the conditional as opposed to the elements array.


Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top