Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one,
I am doing a library management project.In front end i have two text boxes one for due date and another for fine details.When due date is entered in the text box, if the due date is less than current date i want fine details should also appear automatically after leaving focus.
I have fixed fine for 1 day as 5 Rs or 5$.It has to calculate no of days and should multiply with the fine amount and total should be displayed in the fine text box.Please any one help me in accomplishing this.

Thank you in advance.
Posted

I would suggest you to use JQuery .ajax() method. Create a HTTP handler that calculates the overdue days and multiply it with the amount of fine per day and return the result. The reason for calculating it on the back-end is that if in future you need to change the amount of fine per day, you will have to change it in the database table only. This[^] is a very good example to start.
 
Share this answer
 
to find date difference you have to work on time span
now your requirement is when you leave your text box result should be displayed this can be done on
Textbox change event and this textbox will be in between update panel Its a ajax Control This Operation is necessary because if you are not going to do this then you have to use button to display result every time so its better to use Ajax Control..

Try It Nd let me know
 
Share this answer
 
Well you can use Normal JavaScript for this.

On the onblur event of the due date textbox, call a Js function which will take the value from the due date textbox and then compare it with the current date and do calculations accordingly.

Below is a sample code which might help:

C#
<asp:textbox id="txtDueDate" runat="server" onblur="CallMe();" xmlns:asp="#unknown"></asp:textbox>
<asp:textbox id="txtFine" runat="server" xmlns:asp="#unknown"></asp:textbox>


Js code:

JavaScript
<script type="text/javascript">
function CallMe(){
var oneDayFine=5;
var dateVariable=document.getElementById('txtDueDate').value;
var dueDate=new Date("dateVariable");
var currentDate=new Date();//Get the current Date
var differenceinDays=Math.Abs(currentDate.getTime()-dueDate.getTime());
if(differenceinDays>0)
{
var totalFine=oneDayFine*differenceinDays;
document.getElementById('txtFine').value=totalFine;
}
else
{
window.alert('No Fine');
}
}
</script>


The only thing you need to take care is that what format is the time coming from your UI. I suggest you use a DateTimePicker instead.The code may not be perfect but it will give you an insight. try it

Anurag
 
Share this answer
 

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