Solved

I need a Javascript for user entry and radio button sum

Posted on 2010-09-21
9
451 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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 500 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to dynamically set the form action using jQuery.

679 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