Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

Calculate fields in aspx

I have a form where the user sets a few decimal fields and if the user tabs through the fields the 'total' field calculates all the fields together and gets set and everything works fine but if they use their mouse this is where my troubles begin. I know it is because of the keyup in my function but I wanted to know if there is something else that I can use like something similar to onblur() maybe? I am new to javascript and jquery so I have no clue so any advice would be great.

Here is my code...
<%--Being used for generating Travel item cost values for the Total--%>
<script type="text/javascript">
    $(document).ready(function () {
        $(".toCalculate").keyup(function () {
            var total = 0;
            $(".toCalculate").each(function (index, item) {
                temp = parseFloat($(item).val());                
                if (isNaN(temp))
                    temp = 0;
                total = total + temp;
            });
            $(".total").val(total.toFixed(2));            
        });
    });
</script>

Open in new window


Thanks for the help!!!
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jknj72
jknj72

ASKER

Neither worked 100% but, believe it or not, I have both of them setup and they work about 90-95% of the different scenarios and that will have to be good enough. They didnt question anything so I think Im good. Thank you both very much for your hep!!
Avatar of jknj72

ASKER

neither was the best solution but it made me choose one so I chose the first one. Again, thanks for your help