I'm working on a script to do some automatic filling. I've ran into a problem that sometimes I won't know the name of a form so its hard for me to do an autofill. Here is the code to fill text from form1 to form2, how can I do the same if the second form has no name? <SCRIPT LANGUAGE=JavaScript> <!-- function fill() { document.form2.name.value=document.form1.name.value; document.form2.age.value=document.form1.age.value; } //--> </SCRIPT> <input type="button" onClick="javascript:fill()" value="Fill Forms"> <form method="get" action="" name="form1"> Name <input name="name" type="text"> Age <input name="age" type="text"> </form> <form method="get" action="" name="form2"> Name 2 <input name="name" type="text"> Age 2 <input name="age" type="text"> </form> Code (markup):
Wouldn't you be able to access the form by something like: document.forms[number].elements[number] For example, document.forms[0].elements[0] would refer to first form, first element. This way, you can code without knowing the element name as well. Hope this helps.