Solved

document.form.something.value?

Posted on 2002-07-21
8
293 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 160 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks again!
0
 
LVL 53

Expert Comment

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

Cd&
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now