|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to find a way to discern the array value of a given form within a document to pass/manipultae into another form within the same document.
e.g. - I am trying to get x from the document.forms[x] for a form named 'form1'; as I need to add one to it and extract information from an unamed form appearing directly after form1. It is not an easy option for me to add the name to the second form, so I would like to take values from it by calling it document.forms[x+1] upon submission of form1. Any help/insight into this would be most appreciated! Yuccatan |
|
#2
|
|||
|
|||
|
I'm not sure about this, but if you only have 2 forms in your page and you don't name either of them, then they'll both become elements in the same form array with an index based on the order they appear in your document. That is, you should be able to refer to your first form as document.forms[0], and your other form as document.forms[1]
Yeah, I checked, try this: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><html> <head> <style><!-- --></style> <title>Forms</title> </head> <body> <form><input type=text></form> <form><input type=text></form> </body> <script language="JavaScript"><!-- document.forms[0].elements[0].value="This is the first Form" document.forms[1].elements[0].value="This is the second Form" //--></script> </html>[/code] |
|
#3
|
|||
|
|||
|
Sorry; I forgot to clarify further on why I need the index value...
I'm implementing this code within a variety of templates, which could have any number of forms before or after the two forms, which would throw off any use of the length or 0 - 1 values... I guess I'm really looking for a relative position solution rather than the arbitrary solutions documented in the Rhino book... Any further suggestions? Thanks for your help/insight! Yuccatan |
|
#4
|
|||
|
|||
|
At some point you're going to have to get way more specific, but whether you like it or not, all the forms in your html page will be referenced as members of a forms array. However, you can still specify your two special forms by name. So to find out the index numbers of your two special forms you could use a script that searches the names of all the forms on the page, and if the name matches the name of your special form just have it return the index number, or whatever it is you need to do after you identify the index of your special forms. Load this page to see what I'm talking about:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><html> <head> <style><!----></style> <title>Forms</title> </head><body> <form name="otherForm"> <input type=text> </form> <form name="form1"> <input type=text> </form> <form name="otherForm"> <input type=text> </form> <form name="form2"> <input type=text> </form> <form name="otherForm"> <input type=text> </form> </body> <script language="JavaScript"><!-- for (i=0;i<document.forms.length;i++) { if (document.forms[i].name=="form1") { alert("the index on this page for "form1" is " + i) } if (document.forms[i].name=="form2") { alert("the index on this page for "form2" is " + i) } } //--></script> </html>[/code] |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Getting the x value from document.forms[x] |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|