Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16410
| From | JJ <jaejunks_at@_googlemail_dot._com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Extracting data from a form |
| Date | 2012-10-05 01:34 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <XnsA0E357D11D116jaejunksgooglemailco@0.0.0.44> (permalink) |
| References | <k4kuc5$pnp$1@gallifrey.nk.ca> |
doctor@doctor.nl2k.ab.ca (The Doctor) wrote:
> We are working with
>
> <html><head>
[snip]
> End HTML
>
> All right we want to incorpration the Quantity Value
>
> So the Total Price = Sum of Quantity (x) * Price (x) .
>
>
> 277 <= x <= 278 .
>
> In this case.
>
> How does one incorporate this into the total?
Use below "count" function replacement. The input quantity value in the
form must be a valid number greater than zero. Otherwise, if it's
negative or invalid number, it will be assumed as zero. The "price277",
"price278" form fields value must be a valid number for the course price,
or the code won't work.
You might want to learn the code instead of copy-paste-forget. Feel free
to ask if you don't understand something.
//courseNumber must be a number or a string of number.
//e.g.: 277, "278", etc.
function getTotalCoursePrice(courseNumber) {
if (calc['price'+courseNumber].checked){
var price = parseInt(calc['price'+courseNumber].value.trim());
var qty = parseInt(calc['quantity'+courseNumber].value.trim());
if (isNaN(qty) || (qty < 0)) qty = 0;
} else {
var price = 0;
var qty = 0;
}
return price * qty;
}
function count() {
var i, result = 0;
//loop the count for course number 277 to 278 inclusive.
for (i = 277; i <= 278; i++) i += getTotalCoursePrice(i);
calc.charge_total.value = result.toFixed(2);
//don't submit if total price is zero
return result > 0;
}
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Extracting data from a form doctor@doctor.nl2k.ab.ca (The Doctor) - 2012-10-04 21:16 +0000
Re: Extracting data from a form Danny <dann90038@gmail.com> - 2012-10-04 15:31 -0700
Re: Extracting data from a form JJ <jaejunks_at@_googlemail_dot._com> - 2012-10-05 01:34 +0000
Re: Extracting data from a form Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-06 19:12 +0100
Re: Extracting data from a form "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-07 07:34 +0000
Re: Extracting data from a form doctor@doctor.nl2k.ab.ca (The Doctor) - 2012-10-08 20:22 +0000
Re: Extracting data from a form "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-08 20:52 +0000
csiph-web