Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Add percentages to calculated value

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 03-14-2013, 08:10 PM PM User | #1 Reflo2 New Coder   Join Date: Mar 2013 Posts: 11 Thanks: 2 Thanked 0 Times in 0 Posts Add percentages to calculated value Hi All I have a form that gives the sum result of a set of inputs (rounded to 2 points as they are currency) How would I add a function to produce % (plus) of the sum total. The percentages don't really matter on this example they are just to show (if anyone can ??) me how it done. Thanks Karen Code: ``` Untitled 1

Total
Total *5%
Total * 23.76%
Total * 2.5%
```
03-14-2013, 08:35 PM   PM User | #2
Philip M
Supreme Master coder!

Join Date: Jun 2002
Location: London, England
Posts: 17,471
Thanks: 200
Thanked 2,469 Times in 2,447 Posts
Quote:
 Originally Posted by Reflo2 How would I add a function to produce % (plus) of the sum total.
Surely this is just basic maths?

Code:
```<script type = "text/javascript">

var amount = 100.80;
var percent = 20;
var newAmount = amount * (percent/100 +1);

</script>```

Quizmaster: Emmental and Double Gloucester are both types of what?
Contestant: Banks.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

 03-15-2013, 12:56 AM PM User | #3 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,941 Thanks: 75 Thanked 4,306 Times in 4,273 Posts Does this code really make sense, even in jQuery? Code: ``` \$(function () { var textBox1 = \$('input:text[id\$=Box1]').keyup(AddItUp); var textBox2 = \$('input:text[id\$=Box2]').keyup(AddItUp); var textBox3 = \$('input:text[id\$=Box3]').keyup(AddItUp); var textBox4 = \$('input:text[id\$=Box4]').keyup(AddItUp); var textBox5 = \$('input:text[id\$=Box5]').keyup(AddItUp); var textBox6 = \$('input:text[id\$=Box6]').keyup(AddItUp);``` ??? Seems to me like that is assigning the result of calling keyup to the six vars. Shouldn't all those lines be more like Code: ``` var textBox1,textBox2,textBox3,textBox4,textBox5,textBox6; ( textBox1 = \$('input:text[id\$=Box1]') ).keyup(AddItUp); etc.``` And is there really any reason to use `\$('input:text[id\$=Box1]')`??? What's wrong with simply `\$("#Box1")`? But now why do it like that, at all? Code: ``` \$(function () { var boxes = []; for ( var b = 1; b <= 6; ++b ) { boxes[b] = \$("#Box"+b); boxes[b].keyup(AddItUp); }``` Though for the life of me I can't see any reason to drag in the entire jQuery library for this simple stuff. __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
 03-15-2013, 01:12 AM PM User | #4 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,941 Thanks: 75 Thanked 4,306 Times in 4,273 Posts Here. No silly jQuery needed. (Not that jQuery is silly, just that it wasn't used for any worthwhile purpose in this page.) And actually tested *AS AN ASP.NET PAGE* (named "junk3.aspx" if you care). This shows the specified percentages being *ADDED* to the total there in each case. If you didn't want them added on, if you just wanted the bare percentages, just change all the 1.xxx numbers in the places in red to 0.xxx instead. Code: ``` Untitled 1

Total
Total *5%
Total * 23.76%
Total * 2.5%
``` __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 02:06 PM.