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

  • SEARCH
  • Home
  • 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 6224187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:37:39+00:00 2026-05-24T08:37:39+00:00

This Javascript which uses functions from jQuery is quite handy but getting feedback on

  • 0

This Javascript which uses functions from jQuery is quite handy but getting feedback on it there is some limitations which I was hoping you guys could help me overcome.

The function basically creates a textbox with a formatted time (HH:MM:SS) so that it is easy for users to enter in times rather than have to use a date time picker which involves lots of clicks.

Code:

//global variable for keeping count on how many times the function is called 
var i = 0;

//for adding formatted time fields
function timemaker()
{

 //creates an input field of text type formatted with a value of "00:00:00"
 var input = $("<input>", 
    {
        name: 'time'+i, // e.g. time0, time1, time2, time3
        value: '00:00:00',
        maxlength: '8',
        size: '6'
    });

    //this function which uses jquery plugin causes the cursor in the field to goto position zero
    //when selected making it easier for the user to enter times and not need to select the correct position
    input.click(function() 
    {

        $(this).prop({
            selectionStart: 0,
            selectionEnd: 0
        });

        //this child function moves the cursor along the text field
        //when it reaches the first ":" it jumps to the next "00"
        }).keydown(function() {

    if (event.keyCode == 9) 
    { 
        return; 
    }

    else
    {
                var sel = $(this).prop('selectionStart'),
                val = $(this).val(),
                newsel = sel === 2 ? 3: sel;
                newsel = sel === 5 ? 6: newsel;

            $(this).val(val.substring(0, newsel) + val.substring(newsel + 1))

            .prop({
                selectionStart: newsel,
                selectionEnd: newsel
            });
    }
});

//this appends the text field to a divved area of the page

input.appendTo(“#events”);
i++;
return;
}

00:00:00

Limitations I need help with

  • Say for example you wanted to enter a time of 12:45:00 , you
    obviously don’t need to enter the seconds part (last “00”) as they
    are already there. So you then decide to tab out of that text field
    but the javascript interprets your “Tab” keypress as an entry and
    deletes a zero from the field causing the value to be like 12:45:0
  • Does not validate inputs for 24 hour format- do you think it will be
    possible to do that? e.g. first number you enter is “2” therefore the
    only options you have are “0,1,2,3”
  • If you make a mistake in the 4th digit and reselect the text field
    you have to enter everything again.
  • 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-24T08:37:41+00:00Added an answer on May 24, 2026 at 8:37 am

    I think the main thing you’re missing that would allow you to implement all those requirements is the argument that jQuery passes to you in your keydown event handler. So, change that line to this:

    .keydown(function(event){
        if (event.keyCode == 9) { return; }
    
        ... the rest of your code ...
    

    and then you can use event.keyCode to identify what was pressed and take actions accordingly. So for example, if event.keyCode == 9 then the user pressed TAB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a component which writes/generates javascript from a server side renderer. This component
In JavaScript this was a cross-browser compatibility issue, so both were used, but there
I already started this in javascript so I don't want to use jquery but
I'm looking for some help converting this from prototype to jQuery. I'm doing some
I have a site which uses a lot of JavaScript (mainly jQuery) and I
I am using a jQuery plugin called: jqtransform This plugin uses JavaScript to apply
I am building a Facebook App which is heavy on Javascript. For this I
This is javascript, but a virtually identical regex is failing in PHP too, so
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I am trying to remove Details from http://localhost:1985/Materials/Details/2/Steel but some how my route doesn't

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.