/    Sign up×
Community /Pin to ProfileBookmark

Getting function SubTotal to work…

Did a search here…
Tried google…

My js:

[Quote]

function setSubTotal(obj)
{
var frm = obj.form;
var fvariable1 = parseFloat(frm.variable1.value);
var fvariable2 = parseFloat(frm.variable2.value);
…..
…..

if(isNaN(fvariable1))
{
frm.subtotal.value = 0;
}
else
{
frm.subtotal.value = (fvariable1) + (fvariable2) + …..;
}

}

[/quote]

My html:

[Quote]

<input name=”subtotal” type=”text” id=”subtotal” size=”4″ onChange=”setSubTotal(this)”>

[/Quote]

I’ve used this pattern before for other calculations and it works fine.
This one doesn’t. What am I missing?

Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzNov 30.2007 — Perhaps you meant to call the function from an event on a different form control?
Copy linkTweet thisAlerts:
@stickyfingersauthorDec 11.2007 — Hi,

Thanks for responding.

Here is my js code. I've included the js for setApplePie to show you that the pattern works for apple pies ordered. fapplepieq is the quantity of apple pies ordered. fapplepiet is the total based on the quantity of apple pies times the price for one:


function setApplePie(obj)

{

var frm = obj.form;

var fapplepieq = parseFloat(frm.applepieq.value);

var fapplepiet = parseFloat(frm.applepiet.value);

if(isNaN(fapplepieq))
{
frm.applepiet.value = 0;
}
else
{
frm.applepiet.value = ((5.95) * fapplepieq);
}

}

function setSubTotal(obj)

{

var frm = obj.form;

var fsubtotal = parseFloat(frm.subtotal.value);

var flargehousesaladt = parseFloat(frm.largehousesaladt.value);

var fsmallhousesaladt = parseFloat(frm.smallhousesaladt.value);

var fporterhousesteakt = parseFloat(frm.porterhousesteakt.value);

var ftbonesteakt = parseFloat(frm.tbonesteakt.value);

var fbakedchickent = parseFloat(frm.bakedchickent.value);

var fbbqchickent = parseFloat(frm.bbqchickent.value);

var ffloundert = parseFloat(frm.floundert.value);

var fcodt = parseFloat(frm.codt.value);

var fmashedt = parseFloat(frm.mashedt.value);

var fricet = parseFloat(frm.ricet.value);

var fcornt = parseFloat(frm.cornt.value);

var fstringbeanst = parseFloat(frm.stringbeanst.value);

var fchoccaket = parseFloat(frm.choccaket.value);

var fapplepiet = parseFloat(frm.applepiet.value);


if(isNaN(flargehousesaladt))
{
frm.subtotal.value = 0;
}
else
{
frm.subtotal.value = ((flargehousesaladt) + (fsmallhousesaladt) + (fporterhousesteakt) + (ftbonesteakt) + (fbakedchickent) + (fbbqchickent) + (ffloundert) + (fcodt) + (fmashedt) + (fricet) + (fcornt) + (fstringbeanst) + (fchoccaket) + (fapplepiet));
}

}
[/Quote]


Here is the html. Again, I've included the html for apple pie to show you that it works:


<select name="applepieq" id="applepieq" onChange="setApplePie(this)">

<option selected value=""></option>

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

</select>

</td>

<td>

<p><input name="applepiet" type="text" id="applepiet" size="4">

</td>

</tr>

<tr>

<td colspan=4>

<h6>Sub-Total:&nbsp;<input name="subtotal" type="text" id="subtotal" size="4" onChange="setSubTotal(this)">&nbsp;</h6><br />
[/Quote]


As you can see I have a field for subtotal. It's the total of all the foods and their quantities that I have on my form. Everything is all in the same form. Why does it work for apple pie (and all the other foods) but not for the sub total of all the totals?

Any help is appreciated...

Thanks.
×

Success!

Help @stickyfingers spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...