Solved

document.form.something.value?

Posted on 2002-07-21
8
299 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
[X]
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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 how to create an extensible mechanism for linked drop downs.
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…

691 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