Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

document.form.something.value?

Posted on 2002-07-21
8
Medium Priority
?
306 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
Industry Leaders: 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 640 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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

636 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