Book Section
-----
TY JavaScript 3rd Ed.
Teach Yourself JS 1.5
Teach Yourself DHTML
Teach Yourself JS 1.3
LLWW: JavaScript

General Section
-----
Discussion Forum
Articles / Tips
JavaScript Links
About the Author
Privacy Policy
Contact Me



Other Sites
-----
Website Workshop
JavaScript Weblog

JavaScript Workshop Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Looping through form fields

 
Post new topic   Reply to topic    JSWorkshop Forum Index -> JavaScript
View previous topic :: View next topic  
Author Message
saurabh
New member
New member


Joined: 01 Oct 2002
Posts: 4

PostPosted: Tue Oct 01, 2002 2:57 pm    Post subject: Looping through form fields Reply with quote

Hi everyone! I have a javascript question and will really appreciate any help.

I have a html form which has 10 different text boxes along with other form elements. These text boxes are named amount1, amount2... amount10. What I want to know is if there is a way I can loop through the values entered in these text boxes when I click the submit button to call the javascript function.

Thanks.
Back to top
View user's profile Send private message
mgm
Site Admin
Site Admin


Joined: 13 Jul 2002
Posts: 304
Location: Salt Lake City, UT

PostPosted: Wed Oct 02, 2002 12:13 am    Post subject: Reply with quote

This should work:
Code:
for (i=1; i<=10; i++) {
  textname = "amount" + i;
  val = document.formname[textname].value;
  alert(val);
}

Replace the alert with whatever you actually plan to do with the values.
_________________
Michael Moncur
Owner and Moderator, The JavaScript Workshop
Read the guidelines before posting: http://www.jsworkshop.com/posting.html
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    JSWorkshop Forum Index -> JavaScript All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
(c) 1997-2002 Starling Technologies and Michael Moncur. Portions (c) Sams Publishing.