Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

document.form.something.value?

Posted on 2002-07-21
8
297 Views
Last Modified: 2007-12-19
Well what I really need to do is to scroll through all my forms which are actually called: form1, form2, form3,... form50.

Now writing:

Value = Value+document.form.form1.value+document.form.form2.value+etc.... Can get tiring.  So I tried this:

for (i=1; i <= MaxForms; i++) {
     if(document.form.dowhat.value=="INSERT"){
     Insert = Insert+document.form.table+i.value+","
     }else{
     
     }
}

Now it gives me 50 values but are undefined.  How do I do something like this?
0
Comment
Question by:joshbm
  • 4
  • 4
8 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7168314
Perhaps something like:

function getAll()
{
str='';
for (i=0;i<document.forms.length;i++)
{
   for (j=0;j<document.forms[i].elements.length;j++)
   {
      str+=document.forms[i].elements[j].value;
   }
}
alert(str);
}

Cd&
0
 
LVL 2

Author Comment

by:joshbm
ID: 7168319
Thanks for your reply COBO.. The only problem is I have some form data that I do not want to go along with it.  So that is why I would like document.form.something+i.value.  I did this before in ASP, but I am moving to JavaScript because I really don't need a Server Side script to load a whole new page.  Before in ASP I had request.form("table" & i).  This worked well.
0
 
LVL 2

Author Comment

by:joshbm
ID: 7168321
I am not advanced in JavaScript.  So you may have the right answer, but I don't know how to make it so it only reads the forms that start with things like table.  IE table+i, table1, table2 etc
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 160 total points
ID: 7168326
If you are trying to use a name with a numeric suffix then perhaps:

somevar1="table"+i;
somevar2="field"+j;
document.forms[somevar1].elements[somevar2].value

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7168329
It will get confused by an expression in the index, but if you set a variable and then use the variable as an index is should work.

Cd&
0
 
LVL 2

Author Comment

by:joshbm
ID: 7168335
Thanks a million.  I really appreciate this!  You did such an awesome reply let me up it 60 pts.
0
 
LVL 2

Author Comment

by:joshbm
ID: 7168337
Thanks again!
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7168349
Glad I could help.  Thanks for the A, and the bonus.  Makes it worth working on Sunday. :^)

Cd&
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question