473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to you dynamically address field from html page

I have a variable number of lines, with each line being a transaction,
displayed in my jsp. Each line has an amount value with the name
equal to the line it is displayed on. For example name=amount0 on
line 1
name=amount1 on line 2, etc...

I am attempting to edit the values in the amount field prior to
submitting the form. I have a for loop that goes through the lines
but haven't been able to come up with a way to dynamically address the
field. In the example below I was hoping that 'i' would append itself
to the field name 'tranLimit'. Unfortunatly, it doesn't. How would I
make the field name variable?


isMoney = /^\d+\.\d{2}$/;

// See list of all accounts available to user
function submit_form() {
continueSubmit = "Y";
rowCount = document.chglimits.rowCount.value;
for(i=0;i<rowCount;i++) {
if(!isMoney.test(document.chglimits."tranLimit"i.v alue)) {
alert('Invalid Dollar Amount');
continueSubmit = "N";
} else {
}
}
if(continueSubmit == "Y") {
document.chglimits.cmd.value = 'chg_tranlimit';
document.forms['chglimits'].submit();
}
}
Jul 20 '05 #1
3 1423
On 23 Jan 2004 12:13:53 -0800, Jon Knutson <jo*********@comcast.net> wrote:
I have a variable number of lines, with each line being a transaction,
displayed in my jsp. Each line has an amount value with the name
equal to the line it is displayed on. For example name=amount0 on
line 1
name=amount1 on line 2, etc...

I am attempting to edit the values in the amount field prior to
submitting the form. I have a for loop that goes through the lines
but haven't been able to come up with a way to dynamically address the
field. In the example below I was hoping that 'i' would append itself
to the field name 'tranLimit'. Unfortunatly, it doesn't. How would I
make the field name variable?


If you used the collection syntax for accessing forms and their controls,
you can build up names with the concatenation operator. Your attempt would
be written:

document.forms['chglimits'].elements['tranLimit' + i].value

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
In article <ee*************************@posting.google.com> ,
jo*********@comcast.net enlightened us with...

I am attempting to edit the values in the amount field prior to
submitting the form. I have a for loop that goes through the lines
but haven't been able to come up with a way to dynamically address the
field. In the example below I was hoping that 'i' would append itself
to the field name 'tranLimit'.
So close...
But close only counts with grenades and horseshoes.
for(i=0;i<rowCount;i++) {
if(!isMoney.test(document.chglimits."tranLimit"i.v alue))


Now come on - you can't just stick a variable name after quotes in JSPs,
either. :)

document.chglimits.elements["tranLimit"+i].value

Note: the above is not good cross-browser syntax.
If supporting non-IE browsers, use
document.forms["chglimits"].elements["tranLimit"+i].value

--
--
~kaeli~
Is it possible to be totally partial?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #3
JRS: In article <ee*************************@posting.google.com> , seen
in news:comp.lang.javascript, Jon Knutson <jo*********@comcast.net>
posted at Fri, 23 Jan 2004 12:13:53 :-
I have a for loop that goes through the lines
but haven't been able to come up with a way to dynamically address the
field.


FAQ, 4.39. Read its FAQ before posting to a newsgroup.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave Nouwens | last post by:
Hi All, Please accept my appologies in advance for what I expect will be a reasonably simple question. I have an html form (which is generated in php) which contains a number of rows (one row...
1
by: jzhang29 | last post by:
I have a JSP page and it contains a dropdown list called Office. What I try to do is: When I select different office from this list, the information of office (address, phone,etc) will be...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
5
by: Mike Dee | last post by:
Is it possible to dynamically create a new form object (form1), then create a new form field object and add it form1, and then add form1 to the current document? I need to do all this in script...
4
by: Mike | last post by:
Hi all, In my recent ASP.NET 2.0 appl, I need to verify that the supplied email address is valid or not. So, here's my situation: - In my <profilearea, I created <isVerifiedproperty. - Suppose a...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
3
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
3
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.