Solved

I need a Javascript for user entry and radio button sum

Posted on 2010-09-21
9
452 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
[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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Analytics - viewing a page 10 83
Passing client data from form to server 5 55
Submitting form with no refresh at the end 2 32
wordpress 4.7.4, theme 8 40
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

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