Solved

I need a Javascript for user entry and radio button sum

Posted on 2010-09-21
9
447 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now