Solved

document.form.something.value?

Posted on 2002-07-21
8
298 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

734 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