wadha alketbi wrote:Now this value (result) saved automatic in the DB but, I want it to appear in the input text direct when the user enters the two dates (start and end).
And which code do you already have so far?
And what about your JSP file? Because that's where the calculated value should be displayed if I understand correctly. The method to calculate the number of required days has no added value for the question you have asked, but the JSP file does matter.
wadha alketbi wrote:so, I want the result of the calculation to be stored in the DB and to be in the input text at the same time.
Why would you want to store a calculated value in your database?
And do you submit your form to calculate the number of required days?
wadha alketbi wrote:Because one of the required field is time spent in days which is (required days).
wadha alketbi wrote:To calculate and to add the values to the DB at the same time.
So the number of required dates will be updated as well when either start or end date is changed (either through the webapp or directly in the database)?
And which page is shown after the insert into the database completes successfully?
So how can you show the number of days in the input field if you just show a message
wadha alketbi wrote:While the user enters 2 dates the result should directly displayed in the input text before the user submit the form
after the user submit the form (Save button), all the values will be saved to the DB
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Then you need to perform an ajax request once both values are entered to retrieve the required days field. Or you could have some javascript to perform the calculation of the number of days client-side. But it makes no sense to send all three values with the form, because a user could change the required days field and provide another (incorrect) value. So you will have to (re)calculate the value before saving it into the database. That's one of the reasons why it doesn't make sense to store calculated values (unless you want to improve the performance).
But I am pretty sure each RDBMS will have several functions to calculate the number of days as well between two dates...