/    Sign up×
Community /Pin to ProfileBookmark

onChange() add total questions

Hello, I am working on the form and it suppost to add a total simultaneously when you check a checkbox. The total displays on a text box. I have the following code..(function and form)

[code=php]
<form action=”scrcregconfirmation.htm” name=”form” method=”post” name=”scrc”>

<input name=”facconregistration” type=”checkbox” id=”facconregistration” value=”include” />
<input name=”facsrcmembership” type=”checkbox” id=”facsrcmembership” value=”include” />
<input name=”stuconregistration” type=”checkbox” id=”stuconregistration” value=”include” />
<input name=”stusrcmembership” type=”checkbox” id=”stusrcmembership” value=”include” />

<input name=”total” type=”text” id=”total” size=”8″ onChange=”getTotal(); return true;” />

<input type=”submit” name=”Submit” value=”Submit” />

</form>

[/code]

and here is the functiion

[B]

function getTotal() {

var currency = “$”;

if(theForm.facconregistration.checked == true)
{
var subtotal1 = 165.00;
}
else if
((theForm.facconregistration.checked == true) && (theForm.facconmembership.checked == false))
{
var subtotal1 = 145.00;
}

if((theForm.stuconregistration.checked == true) && (theForm.stuconmembership.checked == true))
{
var subtotal2 = 100.00;
}
else if
((theForm.stuconregistration.checked == true) && (theForm.stuconmembership.checked == false))
{
var subtotal2 = 10.00;
}

var total = subtotal1 + subtotal2;
document.form.total.value = currency + total.toFixed(2);

}

[/B]

Does anyone know what im missing…thanks!!!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JonaJan 15.2005 — [font=trebuchet ms]Use[/font]

<i>
</i>onclick="getTotal()"


[font=trebuchet ms]On all of your checkboxes, and remove:[/font]

<i>
</i>onchange="getTotal(); return true;"


[font=trebuchet ms]from your text box. Each time the function runs, it will upate the text box, and the textbox will change, which may possibly invoke the onchange event to re-evaluate the form and result in an infinite loop.[/font]
×

Success!

Help @vicpal25 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...