Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jquery edit in place: start_time, end_time

Posted on 2013-06-01
11
374 Views
Last Modified: 2013-07-25
I have used jquery edit in place
to update mysql database value without refeshing the page for one value

textbox_start_time (datetime mysql)
textbox_end_time (datetime mysql)
time (difference of end_time, start_time) field value in mysql (int seconds)

total_time (sum of all the time)
total time is not a field value in mysql (but maybe I could create if necessary)

is there a way to use jquery_edit_in place to change time, total_time without a screen refresh by just changing start time
0
Comment
Question by:rgb192
11 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39213381
So basically on change of start time recalculate total time?
What is total time? Hours, minutes, days...?
0
 

Author Comment

by:rgb192
ID: 39213521
total time is int

function str_to_time($int){
$hrs=floor($int/3600);
$mins=($int-$hrs*3600)/60;
$str=$hrs.":".($mins<10?"0".$mins:$mins);
return $str;
}
0
 

Author Comment

by:rgb192
ID: 39229434
int and then taken to a function that returns string in the format hours:minutes
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 55

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 39231859
Not with inplace editor but fairly simple to do it with standard jquery

Something like this would do it - obviously without seeing your code I can't give you an exact example
$(function() {
  $('#startime').blur(function () {
     $('#totaltime').val($('#endtime').val() - $('#startime').val());
  });
});

Open in new window

0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39234613
I'm not certain I get the question, but I think I might be able to paraphrase.  Let me know if this makes sense.

When the page is loaded, the cursor focus is placed on a "textarea" control.  The start_time is captured at this point.  

When the client moves the cursor away and clicks something else (maybe a "submit" control), the textarea loses focus.  The end_time is captured at this point.

In JavaScript the times are captured in milliseconds according to the time settings of the client computer.  So we would subtract the start_time from the end_time to get the number of elapsed milliseconds, then divide that number by 1,000 to get the number of elapsed seconds.  This would tell us how long it took the client to type or paste the information into the textarea.

Similarly, we could capture the start_time when the document is ready and the computation could tell us how long it took the client to fill out an entire form (not just a single textarea).

Risks to data accuracy:  The client time settings might be wrong, but are usually right, and are usually set to a locale timezone.  And if all we need is elapsed time, we do not need to worry about the client settings.  The client could focus, blur and refocus the textarea several times.  A single start and stop time capture would not account for this.
0
 

Author Comment

by:rgb192
ID: 39241544
start_time and end_time are mysql database values for a timesheet program

for example when a worker went to work, and when the worker left work
total_time_day is the difference
already using a defined timezone

total_time is the sum of all the times
0
 

Author Comment

by:rgb192
ID: 39241555
$(function() {
  $('#startime').blur(function () {
     $('#totaltime').val($('#endtime').val() - $('#startime').val());
  });
});

do I have a div called total time

<div id='total time'>
</div>
or
<div class='total time>
</div>
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39242044
do I have a div called total time
I give up - do you?
The id in my post was supposed to refer to an <input /> element. Basically it is saying when the <input id="startime" /> looses focus then calculate the rest.

As I mentioned before I am having to guess how your page is marked up so this may not be right for what you want but it illustrates the principle.
0
 

Author Comment

by:rgb192
ID: 39261192
total_time_day is the difference (many values)

I have a div called total time which is the sum of all the time of many total_time_day
which is one sum of all the times in the column
0
 

Author Closing Comment

by:rgb192
ID: 39356109
this could implement start_time and end time

I have problems using this jquery sample with my code, but I see how it could function.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question