Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3874462
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:09:16+00:00 2026-05-19T22:09:16+00:00

Thanks in advance for any help… I’m trying to (1) generate a begin time

  • 0

Thanks in advance for any help…

I’m trying to (1) generate a begin time and end time for a form, (2) find the difference between the two, and (3) add the difference to a new input.

Here’s what I have so far:

<a href="#" id="starttime">Begin time</a>
<input id="starttimeinput" name="starttimeinput" type="text" value="">
<script>
    $("#starttime").click(function () {
         var begintime = event.timeStamp;
         $("#starttimeinput").val(begintime);
    });
</script>
<a href="#" id="endtime">end time</a>
<input id="endtimeinput" name="endtimeinput" type="text" value="">
<script>
    $("#endtime").click(function () {
         var endtime = event.timeStamp;
         $("#endtimeinput").val(endtime);
    });
</script>
<input id="totaltime" name="totaltime" type="text">
<script>
    $("#totaltime").focus(function () {
       var begintime = $("#starttimeinput").val();
       var endtime = $("#endtimeinput").val();
       var totaltime = endtime - begintime;
       $("#totaltime").val(totaltime); 
     });     
</script>

The first part works (entering the timestamps into the beginning time and end time inputs). I’ve never worked with numbers before and can’t figure out the second part. The result that comes up is “NaN”.

Also this might be useful to know the the time between when the links are clicked should be around 30 seconds…

Thanks much for any help you guys have answered so many questions of mine without me having to post!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:09:16+00:00Added an answer on May 19, 2026 at 10:09 pm

    You need to parseInt() the times back out, otherwise they’re just strings (as returned by .val()).

    $("#totaltime").focus(function () {
        var begintime = parseInt($("#starttimeinput").val(), 10),
            endtime = parseInt($("#endtimeinput").val(), 10),
            totaltime = endtime - begintime;
        $("#totaltime").val(totaltime); 
     });
    

    Personally, I’d sooner just store the begintime and endtime values myself, rather than in text inputs (why does the user need to see them, anyway?). Like this:

    var begintime,
        endtime;
    $("#starttime").click(function (event) {
         begintime = event.timeStamp;
         //$("#starttimeinput").val(begintime);
    });
    
    $("#endtime").click(function (event) {
         endtime = event.timeStamp;
         //$("#endtimeinput").val(endtime);
    });
    
    $("#totaltime").focus(function () {
        $("#totaltime").val(endtime - begintime); 
    });
    

    On a side note, I would recommend moving your jQuery code out of inline <script> tags and into an external JS file. This makes for more maintainable markup and JS. Just wrap all of your JS code in a document ready handler:

    $(document).ready(function () {
        /* your code here */
    });
    

    or, more concisely,

    $(function () {
        /* your code here */
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

thanks in advance for any help I am trying to figure out how to
Thanks in advance any help. I'm trying to get one of my controller methods
Thanks in advance for any help. I am trying to figure out how to
I am using c# .net. Thanks in advance for any help. I have searched
Thanks for any help in advance, I can't wrap my SQL skills around this
Thanks in advance for any help. :) Ok, here's my problem. Simplified version of
Hey guys, thanks in advance for any help or input. I am having trouble
Hi thanks in advance for any help. I have two images of a coin
Thanks in advance for any help. This has me confused as I've used the
Thanks in advance for any help you can provide! I have a website built

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.