HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 14th, 2000, 01:59 PM
yuccatan yuccatan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Boston, MA
Posts: 6 yuccatan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 8 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old July 14th, 2000, 02:09 PM
billyo billyo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 114 billyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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]

Reply With Quote
  #3  
Old July 14th, 2000, 02:17 PM
yuccatan yuccatan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Boston, MA
Posts: 6 yuccatan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 8 sec
Reputation Power: 0
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



Reply With Quote
  #4  
Old July 14th, 2000, 06:11 PM
billyo billyo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 114 billyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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]

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > Getting the x value from document.forms[x]


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway