Solved

JavaScript Math function is not working

Posted on 2009-05-05
5
279 Views
Last Modified: 2013-12-07
I inherited a javaScript function that runs in one of our registration pages. The purpose of the function is that when someone checks a box or enters a number into one of the text fields, it is supposed to calculate the sum total and populate a "total" field at the bottom of the page. The function *seems* to work in IE, but not in Firefox and I can't seem to track down why. I'm not a big expert in JavaScript, but I know enough to get by. This code is ancient, so it's probably just some keyword that has been discontinued during the last 4 releases or so. Help!

The second function is just supposed to set a value in a text field. I'm not sure if it's the function itself, or how it's being called, but it doesn't work in either Firefox or IE.

An example of the way these functions are being called is as follows:
<input onClick="calcSum();setFoursome()" name="sponsoropp1" type="checkbox" id="sponsoropp1" title="7500" value="$7,500 Champion Level">
function calcSum() {
var tSum = parseInt(regForm.total.value);
var singles = parseInt(regForm.singles.value) * 275;
var dinnerseats50 = parseInt(regForm.dinnerseats50.value) * 50;
var donation = parseInt(regForm.donation.value);
var sponsoropp1=0;
var sponsoropp2=0;
var sponsoropp3=0;
var sponsoropp4=0;
var sponsoropp5=0;
var sponsoropp6=0;
var sponsoropp7=0;
if (regForm.sponsoropp1.checked) {
	var sponsoropp1 = parseInt(regForm.sponsoropp1.title);
	}
if (regForm.sponsoropp2.checked) {
	var sponsoropp2 = parseInt(regForm.sponsoropp2.title);
	}
if (regForm.sponsoropp3.checked) {
	var sponsoropp3 = parseInt(regForm.sponsoropp3.title);
	}
if (regForm.sponsoropp4.checked) {
	var sponsoropp4 = parseInt(regForm.sponsoropp4.title);
	}
if (regForm.sponsoropp5.checked) {
	var sponsoropp5 = parseInt(regForm.sponsoropp5.title);
	}
if (regForm.sponsoropp6.checked) {
	var sponsoropp6 = parseInt(regForm.sponsoropp6.title);
	}
if (regForm.sponsoropp7.checked) {
	var sponsoropp7 = parseInt(regForm.sponsoropp7.title);
	}
 
tSum = Math.round((singles+sponsoropp1+sponsoropp2+sponsoropp3+sponsoropp4+sponsoropp5+sponsoropp6+sponsoropp7+dinnerseats50+donation)*100)/100;
 
regForm.sum_singles.value = singles;
regForm.sum_sponsoropp.value = sponsoropp1+sponsoropp2+sponsoropp3+sponsoropp4+sponsoropp5+sponsoropp6+sponsoropp7;
regForm.sum_dinnerseats50.value = dinnerseats50;
regForm.total.value = tSum;
 
function setFoursome() {
	if ((regForm.sponsoropp1.checked) || (regForm.sponsoropp2.checked) || 
	(regForm.sponsoropp3.checked) || (regForm.sponsoropp4.checked) || 
	(regForm.sponsoropp5.checked) || (regForm.sponsoropp6.checked)) {
				
	regForm.golfer1.value = "Enter full name";
	regForm.golfer2.value = "Enter full name";
	regForm.golfer3.value = "Enter full name";
	regForm.golfer4.value = "Enter full name";
	}
        }
}

Open in new window

0
Comment
Question by:vcbertini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 24305786
Add this line after line 35 (i.e., tSum = ...) and we'll see what the values are, or if is failing before this point.
alert( 'singles       = ' + singles       + '\n' +
       'sponsoropp1   = ' + sponsoropp1   + '\n' +
       'sponsoropp2   = ' + sponsoropp2   + '\n' +
       'sponsoropp3   = ' + sponsoropp3   + '\n' +
       'sponsoropp4   = ' + sponsoropp4   + '\n' +
       'sponsoropp5   = ' + sponsoropp5   + '\n' +
       'sponsoropp6   = ' + sponsoropp6   + '\n' +
       'sponsoropp7   = ' + sponsoropp7   + '\n' +
       'dinnerseats50 = ' + dinnerseats50 + '\n' +
       'donation      = ' + donation      + '\n' +
       'tSum          = ' + tSum          )

Open in new window

0
 
LVL 10

Accepted Solution

by:
bugada earned 125 total points
ID: 24305971
I think that the second funcion should not be put into the first... check brackets
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24306013
bugada, good catch.

Line 53 (the closing curly brace) should be move ahead of line 42 (the function setFourSome() line
0
 

Author Comment

by:vcbertini
ID: 24306039
Actually, I did move the bracket - it looked strange being embedded like that, and now it seems to be working. I kick myself if that was the actual problem.  I added the alert comment above and tested it. All the variables are coming back okay now.
0
 

Author Closing Comment

by:vcbertini
ID: 31578047
Thank you. What a simple thing. I was looking for something more complex.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I had to do a bit of research to find the answer to this question so I thought I'd share my results.  Due to our outdated mainframe systems, we need to downgrade IE9 to IE8 in order to stay compatible.  We also needed to downgrade Java.  In order to…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question