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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:50:07+00:00 2026-05-23T23:50:07+00:00

Environment: Please use IE for testing it Requirement: I have an alert message which

  • 0

Environment:
Please use IE for testing it

Requirement:
I have an alert message which checks if user enters a value less than 8 digit – user wont be able to move to next field….he should remain on same field.

Problem:
Everything is fine with the functionality except one thing – when user enters any value in a textfield less than 8 digits he gets his foucs back in such a manner than the cursor moves to the first letter of the entered value whereas it should go back to the last letter of the entered valued.

Code:

<html>
<body>
<script>
function checkField(field) {

        if (field.value.length < 8) {
            // Toggle the active element's blur off and back on after the next blur
            var active = document.activeElement;
            if (active && active !== field) {
                var blur = active.onblur || function(){};
                active.onblur = function(){ active.onblur = blur };
            }
            field.focus();
            alert("cannot be less than 8 digits");
        } 
    }

</script>
<input type="text" id="test1" onblur='return checkField(this);'> 
<br/>
<input type="text" id="test2" onblur='return checkField(this);'>
</tr>
</table>
</body>
</html>
  • 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-23T23:50:09+00:00Added an answer on May 23, 2026 at 11:50 pm

    It’s a hack, but this works – add an onfocus listener to replace the value with itself, and IE will behave by putting the cursor at the end – onfocus="this.value = this.value;":

    Used like this:

    <input id="test1" type="text" value="whatever" onblur="return checkField(this);" onfocus="this.value = this.value;" />
    

    If you ever plan to migrate to JQuery (which I recommend), check out this plugin:

    // jQuery plugin: PutCursorAtEnd 1.0
    // http://plugins.jquery.com/project/PutCursorAtEnd
    // by teedyay
    //
    // Puts the cursor at the end of a textbox/ textarea
    
    // codesnippet: 691e18b1-f4f9-41b4-8fe8-bc8ee51b48d4
    (function($)
    {
        jQuery.fn.putCursorAtEnd = function()
        {
        return this.each(function()
        {
            $(this).focus()
    
            // If this function exists...
            if (this.setSelectionRange)
            {
            // ... then use it
            // (Doesn't work in IE)
    
            // Double the length because Opera is inconsistent about whether a carriage return is one character or two. Sigh.
            var len = $(this).val().length * 2;
            this.setSelectionRange(len, len);
            }
            else
            {
            // ... otherwise replace the contents with itself
            // (Doesn't work in Google Chrome)
            $(this).val($(this).val());
            }
    
            // Scroll to the bottom, in case we're in a tall textarea
            // (Necessary for Firefox and Google Chrome)
            this.scrollTop = 999999;
        });
        };
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a card-game application which makes use of Single Table Inheritance. I have
I have a game built in a java environment and I use JVM. I
PLEASE NOTE THAT I CANNOT USE 'find' IN THE TARGET ENVIRONMENT I need to
Can someone please guide me regarding which touch framework (javascript) I should use to
Please excuse me, today is my first day trying to setup a CI environment
Environment: Team Foundation Server 2005 Visual Studio 2008 I have a reasonably large project
Can somebody please explain all the steps involved in setting up ATG development environment
I am new to the .NET environment. I have not used vs 2008 much
Please provide guidelines on when to use DSV's as opposed to database views. Any
Today I have started with setting up of Android Development Environment using Eclipse for

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.