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 6138725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:54:09+00:00 2026-05-23T17:54:09+00:00

This jquery code below is for a text input box to help users enter

  • 0

This jquery code below is for a text input box to help users enter times in a formatted way.

I have tested it on here

http://jsfiddle.net/nNpjm/2/

I am now wanting to include it in my html form now however I do not know where it would go?

Should it go in the onchange tag?

input.click(function() {

        $(this).prop({
            selectionStart: 0, //moves cursor to poition zero in input box
            selectionEnd: 0
        });

    }).keydown(function() {

        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
        });
    });

Thanks

  • 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-23T17:54:09+00:00Added an answer on May 23, 2026 at 5:54 pm

    To get the ball rolling you can simply place the javascript below your form on the same page. You’ll eventually want to place all your javascript in external .js files and include them via <script src="my_javascript_file.js"></script>

    I’ve included your script below. You’ll notice that it’s wrapped in CDATA tags – this is a fail-safe to handle an XHTML doctype so that the XML parser ignores the script completely and does not fail when it encounters unfamiliar characters:

    <form id="form" method="post" action="whatever.html">
        <!-- additional fields, submit button, etc -->
    </form>
    <script type="text/javascript">
    /* <![CDATA[ */
        var input = $("<input>", { //this bit will be removed in the form
            name: 'time',
            val: '00:00:00',
            maxlength: '8',
            size: '5'
        });
    
        input.click(function() {
    
            $(this).prop({
                selectionStart: 0,
                selectionEnd: 0
            });
    
        }).keydown(function() {
    
            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
            });
        });
    
        $(function(){
            $('#form').append(input);
        });
    
    /* ]]> */
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this javascript code below that uses jquery, it is suppoed to be
Is there a better way to do this jquery code? Currently I have to
I have an issue with this jquery code below. Please give me advice or
I have this code : #bottom-div { z-index:999 } <input type=text id=main /> <div
My jquery code below switches a state dropdownlist out with a state input text
I have this jQuery code that queries an API on a keyup event (via
On my main page I have this jquery code which does an ajax call
I have this jQuery datepicker code that initially set the minDate of the datepicker.
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I implemented this Jquery show/hide code and everything works fine except that the box

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.