Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   How to you dynamically address field from html page (http://www.velocityreviews.com/forums/t875376-how-to-you-dynamically-address-field-from-html-page.html)

Jon Knutson 01-23-2004 08:13 PM

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();
}
}

Michael Winter 01-23-2004 08:37 PM

Re: How to you dynamically address field from html page
 
On 23 Jan 2004 12:13:53 -0800, Jon Knutson <jon.knutson@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.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

kaeli 01-23-2004 08:57 PM

Re: How to you dynamically address field from html page
 
In article <eed9781a.0401231213.581843c@posting.google.com> ,
jon.knutson@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


Dr John Stockton 01-24-2004 02:54 PM

Re: How to you dynamically address field from html page
 
JRS: In article <eed9781a.0401231213.581843c@posting.google.com> , seen
in news:comp.lang.javascript, Jon Knutson <jon.knutson@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.


All times are GMT. The time now is 11:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.