Solved

I need a Javascript for user entry and radio button sum

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

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
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ā€¦
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

695 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