Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > help - can anyo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 35520 of 36205
Post > Topic >>

help - can anyone tell me how to get this code snippet to work

by lawrencef@[EMAIL PROTECTED] May 7, 2008 at 06:28 PM

I=92m new to JavaScript and am trying to creating a dynamic web form in
a number of layers. From what I've read, to submit the entire form I
need to have all the fields (that are in all the different layers on
the page), present in the main form as hidden fields. I've done this
and now and trying to write a function to loop through all the layers
on the page and then all the elements within those layers and copy the
field value to the hidden field of the same name in the main form on
the page. Problem is I don=92t know how to concatenate a variable into a
code statement in JavaScript (assuming that=92s how you term it). ie see
the script below =96 in the last line of the script I'm trying to place
2 variables into the statement ie document.MAINFORM.elements.ELNAME.
as it's currently written it causes error because mainform and elname
are taken literally and there is no form named mainform and no element
named elname so I'm assuming I need to amend this line so that the
assigned values for these 2 variables are read instead of the literal
values. Can anyone point me in right direction or can advise on
correct way to do what I'm trying to do if I'm completely barking up
the wrong tree.


function populatemainform(mainform)
{
	for (var f =3D 0; f < document.forms.length; f++) //loop thru all the
forms in the document (except main one)
	{
		if (document.forms[f].name =3D=3D mainform)
		{
			continue  //skip loop if current form is the main form of the page
		}
		else
		{
			for (var e =3D 0; e < document.forms[f].elements.length; e++) //loop
thru all elements in the form.
			{
				var elname =3D document.forms[f].elements[e].name // assign current
element name to elname variable
				document.mainform.elements.elname.value =3D
document.forms[f].elements[e].value;
				}
			}
		}
	}
}
 




 6 Posts in Topic:
help - can anyone tell me how to get this code snippet to work
lawrencef@[EMAIL PROTECTE  2008-05-07 18:28:59 
Re: help - can anyone tell me how to get this code snippet to wo
apatheticagnostic <apa  2008-05-07 19:22:08 
Re: help - can anyone tell me how to get this code snippet to wo
"Tom de Neef" &  2008-05-08 09:10:59 
Re: help - can anyone tell me how to get this code snippet to wo
apatheticagnostic <apa  2008-05-08 02:01:48 
Re: help - can anyone tell me how to get this code snippet to wo
"Tom de Neef" &  2008-05-08 12:24:47 
Re: help - can anyone tell me how to get this code snippet to wo
apatheticagnostic <apa  2008-05-08 11:28:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 7:17:37 CDT 2008.