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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:07:26+00:00 2026-05-19T12:07:26+00:00

I have a form, and I want to dynamically display certain elements of the

  • 0

I have a form, and I want to dynamically display certain elements of the form as soon as they are filled out.

Imagine if I had a text input for your name. As you type, I also want your name to appear in a different part of the webpage.

How would I accomplish this in the simplest manner?

  • 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-19T12:07:26+00:00Added an answer on May 19, 2026 at 12:07 pm

    (See below for an update, I realized later I’d completely forgotten to handle pasting text into the field using a mouse action.)

    You can hook the keypress event (you’ll probably want keydown and keyup as well) on the text input field and use it to trigger an update of a DOM element elsewhere. For instance:

    var nameField = document.getElementById('nameField');
    nameField.onkeydown = updateNameDisplay;
    nameField.onkeyup = updateNameDisplay;
    nameField.onkeypress = updateNameDisplay;
    function updateNameDisplay() {
        document.getElementById('nameDisplay').innerHTML = this.value || "??";
    }
    

    Live example

    That’s a very basic example using a DOM0-style event handler (the “onXyz” property, which I don’t normally like). The simplest way to do these things is to use a library like jQuery, Prototype, YUI, Closure, or any of several others. They’ll smooth over browser differences for you and let you focus on what you’re actually trying to do.

    Here’s the above using jQuery:

    $('#nameField').bind('keydown keyup keypress', function() {
        $('#nameDisplay').html(this.value || "??");
    });
    

    Live example


    Update: Actually, the above will miss things like pasting into the field using the mouse. You’d think a change handler would be good for this, but it doesn’t necessarily fire until focus leaves the field, so it’s not uncommon to use a timed process like this:

    JavaScript, no library:

    var nameField = document.getElementById('nameField');
    var lastNameValue = undefined;
    
    updateNameDisplay();
    
    setInterval(updateNameDisplay, 100);
    
    function updateNameDisplay() {
      var thisValue = nameField.value || "??";
      if (lastNameValue != thisValue) {
        document.getElementById('nameDisplay').innerHTML = lastNameValue = thisValue;
      }
    }
    

    Live example

    You’ll want to avoid having a separate one of these for each field (instead, use a single timer for all of them) and you’ll want to adjust the timer according to what you actually need — be sensitive to the fact that when you’re doing this, you’re consuming resources. If you’ll want to stop the check at some stage (and it’s a good idea), save the return value from setInterval:

    var timerHandle = setInterval(updateNameDisplay, 100);
    

    …and stop the loop like this:

    clearInterval(timerHandle);
    timerHandle = 0;
    

    Here’s a more complete example of dynamically watching fields, only using the timer when a field has focus. I’ve used jQuery for this example because it simplifies it and you did ask for simple (if you use another library or don’t use any library, you can probably port this easily enough; the main place jQuery is useful in this case is in finding the inputs within the form):

    jQuery(function($) {
      var formTimer = 0,
          currentField,
          lastValue;
    
      updateWatchingIndicator();
      $('#theForm :input')
        .focus(startWatching)
        .blur(stopWatching)
        .keypress(updateCurrentField);
    
      function startWatching() {
        stopWatching();
        currentField = this;
        lastValue = undefined;
        formTimer = setInterval(updateCurrentField, 100);
        updateWatchingIndicator();
      }
    
      function stopWatching() {
        if (formTimer != 0) {
          clearInterval(formTimer);
          formTimer = 0;
        }
        currentField = undefined;
        lastValue = undefined;
        updateWatchingIndicator();
      }
    
      function updateCurrentField() {
        var thisValue;
    
        if (currentField && currentField.name) {
          thisValue = currentField.value || "??";
          if (thisValue != lastValue) {
            lastValue = thisValue;
            $('#' + currentField.name + 'Display').html(thisValue);
          }
        }
      }
    
      function updateWatchingIndicator() {
        var msg;
    
        if (currentField) {
          msg = "(Watching, field = " + currentField.name + ")";
        }
        else {
          msg = "(Not watching)";
        }
        $('#watchingIndicator').html(msg);
      }
    
    });​
    

    Live example

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

Sidebar

Related Questions

I have form with multiple input type=radio with text next to them. I want
Okay all, I have a form that I want users to fill out. When
In my view, I have a form I want to dynamically render. This form
I have form and form text field which generates dynamically using JSP. And I'm
I have a scenerio where I want to dynamically render a custom form object.
I have several DropDownLists on a form which are dynamically populated as they move
I have this code: http://jsfiddle.net/J6vzU/1/ I want to dynamically display thumbnail of uploaded file
I have form and I want to send values from it with ajax to
i have a form and want to submit it with a script. i'm going
I have form with few buttons and I want to know what button is

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.