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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:44:50+00:00 2026-05-28T06:44:50+00:00

When a web form is written to the browser, the browsers remembers what the

  • 0

When a web form is written to the browser, the browsers remembers what the initial values are of a text INPUT box. ie. when it receives HTML like this:

<input type="text" value="something">

The browser remembers “something” as the initial/default value. When the user starts typing over it, then hits ESC, the browser reverts the field to the initial value (or blank if it was initially blank of course).

However, when creating a text input box programatically, hitting ESC always seems to blank the box, even if I create it with a default value like so:

$('<input type="text" value="something">')

The browser doesn’t count this as a default value and doesn’t revert to it when hitting ESC. So my question is, is there a way to create a text box in code and somehow assign it a default value, so the ESC key works as if the browser received it in the HTML document?

  • 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-28T06:44:51+00:00Added an answer on May 28, 2026 at 6:44 am

    This esc behavior is IE only by the way. Instead of using jQuery use good old javascript for creating the element and it works.

    var element = document.createElement('input');
    element.type = 'text';
    element.value = 100;
    document.getElementsByTagName('body')[0].appendChild(element);
    

    http://jsfiddle.net/gGrf9/

    If you want to extend this functionality to other browsers then I would use jQuery’s data object to store the default. Then set it when user presses escape.

    //store default value for all elements on page. set new default on blur
    $('input').each( function() {
        $(this).data('default', $(this).val());
        $(this).blur( function() { $(this).data('default', $(this).val()); });
    });
    
    $('input').keyup( function(e) {
        if (e.keyCode == 27) { $(this).val($(this).data('default')); }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net web form with an html input and button at the
I have a mechanize script written in python that fills out a web form
After my web form is submitted, a regex will be applied to user input
I've got a web form with Password and Confirm Password text boxes. I've got
I've written a bookmarlet to open a user defined web link, in this specific
Say I have a mobile web app written using JQuery Mobile, this app retrieves
I've just written (in Perl) a simple web service that displays a web form
I have written a jquery script to dynamically load a form on a web
Ok. The question is. We have a web app written in pure HTML &
What might be changing the DOM of a web page after the browser receives

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.