Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Asp.net to build a loan calculator where through CNIC search it will calculate all fields as well as fetch other details from database.

Now i have a situation where i am stuck,

I have a table in the database which tells how much tax will be deducted based on income. I am fetching the Income automatically on the frontend on cnic search using JavaScript. Now i want to do two things. 1. When the Income is searched i want to automatically calculate the tax aswell based on that database table and display at frontend. 2. Lets say wrong income was fetched using the cnic search, now when the user updates income on frontend a onkeyup event should get fired and the tax should be calculated on the runtime.

Below is my JavaScript Code, here tax_income is used to calculate the tax based on the database table.

var start=0;
var v_tfx=0;
var rate=0;
function SearchRefNo(btn) {
btn = $(btn);
var input = btn.prev();
Proxy('CI_InputRefNo&REF_NO=' + input.val(), { Inf: '' }, function (ds) {

    var res=ds[0];

    start=ds[1][0]['START'];
    v_tfx=ds[1][0]['FIXED_TAX'];
    rate=ds[1][0]['RATE'];
    tax_income =(((res[0].GINCOME * 12) - start) * rate + v_tfx / 12);


    var group = btn.parents('[group-no]:first');
    if (res != null) {
    $('.customer-name').val(res[0].CUSTOMER_NAME);
    $('.cnic').val(res[0].CNIC_NUMBER);
    $('.dob').val(res[0].DOB);
    $('.g-income').val(res[0].GINCOME);
    $('.deduction').val(res[0].DEDUCTION);        
    $('.net-income').val(res[0].NET_INCOME);
    $('.t-income').val(res[0].T_INCOME);
}
});}


And since, i want to calculate the tax if user manually inputs in the gross income field therefore i have used repeater below to fetch the Income Tax Rate table through a repeater.

<script type="text/javascript">
    var markers = [];

    <asp:Repeater ID="rptMarkers" runat="server">
        <ItemTemplate>
                markers.push({"Start": '<%# Eval("START") %>',"Fixed_Tax": '<%# Eval("FIXED_TAX") %>',"Rate": '<%# Eval("RATE") %>',"W_E_F": '<%# Eval("W_E_F") %>'});
        </ItemTemplate>
    </asp:Repeater>
</script>


What I have tried:

Tried the code that i have pasted
Posted
Comments
Sinisa Hajnal 27-Feb-18 3:34am    
Have the server assemble the array and just emit it into the script, your repeater wastes lots of time with something server could do in milliseconds. Other than that, calculation should be straightforward with onblur or onkeypress (Enter charcode 13) calling the function to recalculate.

Which part of your code doesn't work? And what error (if any) do you get?
Faran Saleem 27-Feb-18 8:09am    
There are around 12 rows in the database table but based on the gross income entered in the text box, the code should check on runtime the closest income in the database table and will select that row, then the formula to calculate tax will use the rate,fixed_tax columns of the same row to calculate the tax and display on text box

How should i do this
Faran Saleem 27-Feb-18 7:59am    
The above code is working fine but i want to calculate on real time with the values of database table and display on frontend.
Whant javaScript code should i write to calculate?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900