Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15782
| From | Mike Winter <usenet@michael-winter.me.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: How to do calculation with dynamic form field names? |
| References | <2f50ffc9-e54f-493b-aae9-378dac92b6c1@z8g2000yql.googlegroups.com> <8un2s.290330$Lp7.53018@fx08.am4> <c40ba0e0-3f3a-4333-b9da-60949a55c236@n9g2000yqn.googlegroups.com> <Tzr2s.523194$6h3.7439@fx25.am4> <8999254d-5896-4ba3-becd-ae08c3b242d0@v15g2000yqi.googlegroups.com> |
| Message-ID | <Wks2s.295006$Xu5.65204@fx10.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2012-09-07 20:57 +0100 |
On 07/09/2012 20:36, justaguy wrote:
> On Sep 7, 3:05 pm, Mike Winter <use...@michael-winter.me.invalid>
> wrote:
>
> [snip]
>
>> If your function is called from the form element's submit or
>> the button's click event handler, then:
>>
>> <form ... onsubmit="return calculateTotal(this.form);">
Sorry, I'm obviously not thinking clearly today. With a form, the value
passed would be simply the object referenced by the this keyword. With a
form control, it would be the expression, this.form
[snip]
> Here's the code that works except that I have a checkbox dynamic field
> name starting with
> "Remove_" keyword, I attempted to determine if some of such checkbox
> has been checked with
> the following line of code to no effect,
> document.forms[0].elements['Remove_' + i]
> or
> document.forms[0].elements['Remove_' + i].checked // this line threw
> an error.
That expression would only produce an error if the control didn't exist.
Are these checkboxes present in every row? If not, you'll need to test
for both the presence of the control and whether it's checked:
var skipRowCheckbox = form.elements['Remove_' + i];
if (skipRowCheckbox && skipRowCheckbox.checked) {
t -= subtotal;
}
Or to reverse the logic, so that the subtotal is only increased if there
is no checkbox, or there is but it's unchecked:
var skipRowCheckbox = form.elements['Remove_' + i];
if (!skipRowCheckbox || !skipRowCheckbox.checked) {
t += subtotal;
}
[snip]
--
Mike Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: How to do calculation with dynamic form field names? Mike Winter <usenet@michael-winter.me.invalid> - 2012-09-07 15:26 +0100
Re: How to do calculation with dynamic form field names? justaguy <lichunshen84@gmail.com> - 2012-09-07 08:03 -0700
Re: How to do calculation with dynamic form field names? Gene Wirchenko <genew@ocis.net> - 2012-09-07 10:05 -0700
Re: How to do calculation with dynamic form field names? justaguy <lichunshen84@gmail.com> - 2012-09-07 11:39 -0700
Re: How to do calculation with dynamic form field names? SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-09-07 21:56 +0200
Re: How to do calculation with dynamic form field names? Mike Winter <usenet@michael-winter.me.invalid> - 2012-09-07 20:05 +0100
Re: How to do calculation with dynamic form field names? justaguy <lichunshen84@gmail.com> - 2012-09-07 12:36 -0700
Re: How to do calculation with dynamic form field names? justaguy <lichunshen84@gmail.com> - 2012-09-07 12:51 -0700
Re: How to do calculation with dynamic form field names? Mike Winter <usenet@michael-winter.me.invalid> - 2012-09-07 20:57 +0100
csiph-web