473,569 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.chglim its.rowCount.va lue;
for(i=0;i<rowCo unt;i++) {
if(!isMoney.tes t(document.chgl imits."tranLimi t"i.value)) {
alert('Invalid Dollar Amount');
continueSubmit = "N";
} else {
}
}
if(continueSubm it == "Y") {
document.chglim its.cmd.value = 'chg_tranlimit' ;
document.forms['chglimits'].submit();
}
}
Jul 20 '05 #1
3 1427
On 23 Jan 2004 12:13:53 -0800, Jon Knutson <jo*********@co mcast.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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
In article <ee************ *************@p osting.google.c om>,
jo*********@com cast.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<rowCo unt;i++) {
if(!isMoney.tes t(document.chgl imits."tranLimi t"i.value))


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

document.chglim its.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************ *************@p osting.google.c om>, seen
in news:comp.lang. javascript, Jon Knutson <jo*********@co mcast.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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
2098
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 per product in the 'products' table). It is generated with the following php
1
3602
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 populated in same JSP page. I have a java bean called officeBean that contains all the office information.
8
4303
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender,...
5
3718
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. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of...
5
2084
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 rather than using the html <form> and related tags. Can this be done to support both IE, Firefox? Any code snippets or samples showing how to do...
4
1914
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 new user has been created. I set the profile.isverified to false. OnCreatedUser event I'll send him an email (to the supplied email address) to...
1
7519
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 having the sql statement dynamically built according to the input provided by the user. I have used the method described here hundreds of times it is...
3
3523
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
3
5247
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 add the pane the remove event does not get handled, though thereafter it is handled without problems....
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.