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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:31:25+00:00 2026-06-01T02:31:25+00:00

In a textbox user can enter date. In OnChange event I am trying to

  • 0

In a textbox user can enter date. In OnChange event I am trying to validate the date using javascript, if it is not a valid date showing an alert message and setting the focus on the textbox.

Here when I enter invalid date and press tab, the onchange events fires , in case of invalid date it does not set focus on the texbox, instead the focus is set on next textbox in the form.

<asp:TextBox ID="txtDateOfBirth" runat="server"
    onchange="validateDate(this)"></asp:TextBox>

function validateDate(sender) {
    if (!Date.parseInvariant(sender.value, "MM/dd/yyyy")) {
        alert("date is incorrect");
        sender.focus();
    }
}
  • 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-06-01T02:31:27+00:00Added an answer on June 1, 2026 at 2:31 am

    Try using onblur instead of onchange:

    <script type="text/javascript">
        check = function (sender) {
            if (sender) {
                alert("check");             
                sender.focus();
            }
        }
    </script>
    <asp:TextBox ID="txtTest" runat="server" onblur="check(this);"></asp:TextBox>
    

    In the above example, focus is returned to the input as expected.

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

Sidebar

Related Questions

i have a single textbox named Keywords. User can enter multiple strings for search.
I need to create a textbox that a user can enter an arbitrary string
I want a functionality ,where user can enter some text in a textbox,and based
I have a textbox where the user can enter URL and button named Check
I have a Textbox in which the user is supposed to enter a date
If I have a textbox where a user can enter multiple emails, i.e. test@test.com
Basically, I have a textbox where a user can enter an ID from a
I need to have a textbox (sort of) where the user can enter text
I have a textbox where a user is supposed to enter a date. How
I've got a textbox where the user can enter text that includes html markup.

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.