Avatar of sam15
sam15
 asked on

Javscript_Func_CalcTotal

Does anyone have any javascript function that can add the billable column in the attached page and display at the bottom textfield on page. The function should run whenever user changes the value in the Codes column. The script should only add billable numbers for codes marked "Y" and exclude other codes.
invoice1.html
JavaScriptHTMLWeb Development

Avatar of undefined
Last Comment
sam15

8/22/2022 - Mon
leakim971

use this : http://www.adobe.com/cfusion/tdrc/index.cfm?product=dreamweaver&loc=en

once you add your new column back here to fight
sam15

ASKER
I did not follow you. I need to install dreamweaver Cs 5.5 for a javascript function that adds totals??
leakim971

no but to add a new column, you don't want to display this column by default?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
sam15

ASKER
I do not understand. This is the screen I have.
The column i want to add is already there named "Billable".
Just need a function that displays the total at bottom field whenever user changes the CODE column.
ASKER CERTIFIED SOLUTION
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sam15

ASKER
it works great. but i should have mentioned we are not allowed to use jquery library  due to some accessibility issues with screen readers. Is it possible to due this with plain javascript only.
leakim971

you can put all the content of the jquery script inside your page in a dedicated (or not) script tag
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
leakim971

jQuery 6.1 : 89,2KB
sam15

ASKER
i am not sure what you mean. If it uses jquery they wont pass it to production system.
Cant this be done with regular Javascript?
leakim971

ok, I think you need to reopen a question, request attention or wait answer from other EE
If you choose to open a new question don't forget to mention you DON'T WANT any JS Framework plugin OR mention which one your production system will accept

>i am not sure what you mean.
jQuery plugin is a javascript code like the one I provided, you can put it in your page the same way you add javascript code you understand

>Cant this be done with regular Javascript?
Yes, but I'm not ready to create a new one because you did not mention you don't want jQuery (or perhaps mootools too and so on)
Your help has saved me hundreds of hours of internet surfing.
fblack61
sam15

ASKER
OK sorry i did not explain that in my question, I will accept the Jquery solution and open another question. You seem very proficient in javscript.

Just curious about jquery solution, do users download this library behind the scene when they open the page? I did not see aplace in yuor script for it.
Does it work with all browsers for all sighted users?

$("select[name='p_lockflag']").change(function() {
    var billable = 0;
    debugger;
    $("select[name='p_lockflag'][selectedIndex=0]").each(function() {
        var b = parseFloat($(this).closest("tr").find("div:eq(5)").text().replace(/,|\$|\s/g,""));
        billable += (isNaN(b)||b.length==0)?0:b;
    });
    $("input[name='p_invoice_total']").val(billable.toFixed(2));
});
sam15

ASKER
BTW, I did encapsulate your script in a script tag in the form and opened the webpage but it did not work. So you have to do other changes in the form for naming elements or firing the function.
I did notice anything in your debugger.

<SCRIPT language="JavaScript"  type="text/javascript">

$("select[name='p_lockflag']").change(function() {
    var billable = 0;
    debugger;
    $("select[name='p_lockflag'][selectedIndex=0]").each(function() {
        var b = parseFloat($(this).closest("tr").find("div:eq(5)").text().replace(/,|\$|\s/g,""));
        billable += (isNaN(b)||b.length==0)?0:b;
    });
    $("input[name='p_invoice_total']").val(billable.toFixed(2));
});

</SCRIPT>
leakim971

>do users download this library behind the scene when they open the page?
jsfiddle site do the job (include the jQuery lib & Co) depend your choice on the left menu
What I want you understand is you can include jQuery code manually in your page, for example the content of this file : http://code.jquery.com/jquery.min.js

<script type="text/javascript">
(function(a,b){function cv(a){return f.isWindow(a)?a:a.nodeType===9?a // first line
.... all jQuery code here
this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f})(window); // last line
</script>

>Does it work with all browsers for all sighted users?
It's should, it's the main purpose of jQuery. jQuery is first Javascript.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
sam15

ASKER
I understand now. So i have to copy/paste the Jquery library to every webpage that uses Jquery. right?
Would not the 80 KB slow down the page though?
leakim971

>So i have to copy/paste the Jquery library to every webpage that uses Jquery. right?
right

>Would not the 80 KB slow down the page though?
http://www.t1shopper.com/tools/calculate/downloadcalculator.php
leakim971

a buggy code will really slowdown the page... :))
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
leakim971

... and I'm sure you can win some bytes somewhere, for example on a logo
sam15

ASKER
Ok, excellent info. I will accept your answer. I posted another question for the plain javascript question if you are interested.

thank you,