[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I need a Javascript for user entry and radio button sum

Posted on 2010-09-21
9
Medium Priority
?
457 Views
Last Modified: 2012-06-21
Client originally wanted sum values entered in radio boxes (at top) to be calculated in "Donation" box at bottom ("R1dollars" starting on line 392). You guys helped me with that.

Now the client has added an additional box where the donor can add an additional numerical contribution manually. (starting line 319)

We need the sum total of the manual input to appear, in addition to the sum of the radio buttons, to be calculated in the bottom Donation box (starting line 392)

page link can be found at:

http://www.littlebabyface.org/dev/reservation.html

As always,
thanks
0
Comment
Question by:chodoy
  • 5
  • 3
9 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 33730623
     var total;
      total = getSelectedvalue('sponsorships');
      total = total + getSelectedvalue('ticketReserve');
      total = total + getSelectedvalue('programAds');
        total = total + document.getElementById('no-attend').value;
      document.getElementById('total').value = total;
0
 

Author Comment

by:chodoy
ID: 33730811
Sorry, when I replace the lines of script the radio buttons still work but when I type an additional number in the "id="no-attend"  text field I get the number appended to the end of the sum and not the sum.
0
 
LVL 4

Expert Comment

by:rstjean
ID: 33731186
replace  
total = total + document.getElementById('no-attend').value;
with
total = parseInt(tota)l + parseInt(document.getElementById('no-attend').value);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:chodoy
ID: 33731318
Sorry, none of these solutions seem to be working. The current solution seems to have totally broken all the radio buttons. I have deleted the site and am reposting the original.

http://www.littlebabyface.org/dev/reservation.html

Does anyone have any ideas?



0
 
LVL 4

Expert Comment

by:rstjean
ID: 33731472

<script type="text/javascript">
function calculateTotal()
{
var total;
total = getSelectedvalue('sponsorships') + getSelectedvalue('ticketReserve')+ getSelectedvalue('programAds');

if (isNaN(parseFloat(document.getElementById('no-attend').value)))
	{
	}
else
	{
	total = parseFloat(total) + parseFloat(document.getElementById('no-attend').value);
	}
document.getElementById('total').value = total
}

then in the no-attend input box, add onchange="calculateTotal();"

Open in new window

0
 

Author Comment

by:chodoy
ID: 33733241
replaced javascript with above script.
dreamweaver reporting an error on line 17

script not working.

Any ideas anywone?
0
 

Author Comment

by:chodoy
ID: 33733523
I now realize that the solutions have not been working because as the user inputs their radio button data, and the separate numerical value, there is no "calculate" button that will create a sum for the two values.

I apologize to the people who have been giving their time to work on this issue.

I have added a line of type (line 325) "Add this amount to my total" and I have uploaded it :
http://www.littlebabyface.org/dev/reservation.html

So I will need a Javascript that will turn the line of type "Add this amount to my total" into a calculate button that will give me the sum of the radio button values to the manual input value
0
 
LVL 4

Accepted Solution

by:
rstjean earned 2000 total points
ID: 33734083
I am sorry that I didn't make my instructions easier.  Change your script to the following:
First change the line 323:
From
<input type="text" name="no-attend" id="no-attend" />
to
<input type="text" name="no-attend" id="no-attend" onchange="calculateTotal();" />

Then change 325:    (by the way, this link might not be understood by the users.)
From
<a href="#">Add this amount to my total.</a>
to
<a href="#" onclick="calculateTotal();">Add this amount to my total.</a>

Then change your javascript to:

<script type="text/javascript">
function calculateTotal()
{
      var total;
      total = getSelectedvalue('sponsorships');
      total = total + getSelectedvalue('ticketReserve');
      total = total + getSelectedvalue('programAds');

       if (!isNaN(parseFloat(document.getElementById('no-attend').value))){
      total = parseFloat(total) + parseFloat(document.getElementById('no-attend').value);
      }
      document.getElementById('total').value = total;
}

function getSelectedvalue(radioName){
      var radios = document.getElementsByName(radioName);
      var radioVal = 0;
      for(var i=0;i<radios.length;i++){
            if(radios[i].checked){
                  radioVal = parseFloat(radios[i].value);
                  break;                  
            }
      }
      return radioVal;
}
</script>

0
 

Author Closing Comment

by:chodoy
ID: 33735609
Thank you rstjean. I am a noob to web design and your patient help means a lot to me. I am taking your suggestion about line 325 and making the appropriate change
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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