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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:29:30+00:00 2026-06-03T15:29:30+00:00

I have a form with three text boxes. I want to have a key

  • 0

I have a form with three text boxes. I want to have a key event on each of them regardless which one they enter in first. Here is my code below:

function showQuoteBox() {
var overlay = '<div id="overlay"></div>';
var quoteBox = '<form id="quoteForm" action="#"><h1>Get a quote from <INSTALLERS NAME></h1><fieldset id="user-details"><label for="inName">Name:</label><input type="text" id="inName" name="name" value="" /><label for="email">Email:</label><input type="email" id="inEmail" name="email" value=""  /><label for="phone">Phone:</label><input type="text" id="inPhone" name"phone" value=""  /><input type="submit" value="Get quote!" name="submit" class="submit" /></fieldset><div id="sent-details"><span id="nameText"><span id="emailText"><span id="phoneText"></span></div></form>'
jQuery(overlay).appendTo('body');
jQuery(quoteBox).appendTo('body');
jQuery(document).ready(function() {
    jQuery('#inName').keyup(function(){
        jQuery('#nameText').html(jQuery(this).val());
    });
    jQuery('#inEmail').keyup(function(){
        jQuery('#emailText').html(jQuery(this).val());
    });
    jQuery('#inPhone').keyup(function(){
        jQuery('#phoneText').html(jQuery(this).val());
    });
});
}

window.onkeyup = function (event) {
   if (event.keyCode == 27) {
      jQuery('#overlay').remove();
      jQuery('#quoteForm').remove();
   }
}

Above is my entire function that is called when a button is clicked. It shows the quoteBox with three inputs. Each input box will allow me to enter text but it will only update the span area for the first one that has been entered. All others will not update if any other text box has a value in.

If I choose to enter an email first it will show in the span, but then when I enter a value in any other text boxes, it won’t listen.

  • 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-03T15:29:31+00:00Added an answer on June 3, 2026 at 3:29 pm

    The behavior you describe — where only one keyup appears to be working — is most likely caused by the fact that you have embedded your 3 SPANS inside one another!

    <div id="sent-details">
        <span id="nameText">
            <span id="emailText">
                <span id="phoneText"></span>
    </div>
    

    Not only that, I don’t see them being closed. SPAN tags are not self closing, and each browser will try to self-correct or interpret this in a different way. Some browsers may try to close them for you.

    Thus, your first keypress event is either overwriting the other 2 SPAN elements, or JavaScript can’t find the elements because your HTML is not valid.

    The correct syntax for your HTML would be:

    var quoteBox = '<form id="quoteForm" action="#">' +
      '<h1>Get a quote from <INSTALLERS NAME></h1>'+
      '<fieldset id="user-details">'+
          '<label for="inName">Name:</label>'+
          '<input type="text" id="inName" name="name" value="" />'+
          '<label for="email">Email:</label>'+
          '<input type="email" id="inEmail" name="email" value=""  />'+
          '<label for="phone">Phone:</label>'+
          '<input type="text" id="inPhone" name"phone" value=""  />'+
          '<input type="submit" value="Get quote!" name="submit" class="submit" />'+
      '</fieldset>'+
      '<div id="sent-details">'+
          '<span id="nameText"></span>'+  // closed tags here
          '<span id="emailText"></span>'+ // closed tags here
          '<span id="phoneText"></span>'+ // closed tags here
      '</div></form>';
    

    More sustainable and maintainable solution:

    As an aside, storing a long string of HTML in a JavaScript variable is a very unsustainable way of working with the markup, as it leads to unreadability, which leads precisely to these sorts of mistakes. Instead, if I were to tackle this problem, I would instead place this HTML on the page, but hide it using display:none. Then, in the function showQuoteBox, I would simply use a CSS class or id selector to unhide that block of code.

    Since the HTML would be in the HTML document where it belongs, it would not only be much more maintainable, but you’ll also make friends with your Web designers, who don’t want to try to reverse engineer your JavaScript.

    <div id="overlay" style="display:none">
        <form id="quoteForm" action="#">
            <h1>Get a quote from <INSTALLERS NAME></h1>
                <fieldset id="user-details">
                    <label for="inName">Name:</label>
                    <input type="text" id="inName" name="name" value="" />
                    <label for="email">Email:</label>
                    <input type="email" id="inEmail" name="email" value=""  />
                    <label for="phone">Phone:</label>
                    <input type="text" id="inPhone" name"phone" value=""  />
                    <input type="submit" value="Get quote!" name="submit" class="submit" />
                </fieldset>
               <div id="sent-details">
                   <span id="nameText"></span>
                   <span id="emailText"></span>
                   <span id="phoneText"></span>
              </div>
          </form>
      </div>
    
    function showQuoteBox() {
         // var overlay = '<div id="overlay"></div>';  <-- don't do this
         // var quoteBox
    
         // instead, use jQuery to unhide your HTML and keep it out of the JavaScript
         $('overlay').show();  
    
         // the rest of your code follows
         ...
     }
    

    Finally, it looks like you’re including your keyup event code inside the function showQuoteBox. The ready method on the jQuery object fires as soon as your page is done loading and the DOM is ready, so registering that event inside a function seems a bit odd.

    In this case, you are registering these events when using jQuery to add some DOM elements to an already-loaded page. Thus, the (document).ready is not only unnecessary, but will likely have problems. If, after following the steps in the previous section, you still have trouble, consider removing the document.ready wrapper as shown in this code block:

    // don't put document.ready around this since it's in a function you're calling to show a form
    jQuery('#inName').keyup(function(){
        jQuery('#nameText').html(jQuery(this).val());
    });
    jQuery('#inEmail').keyup(function(){
        jQuery('#emailText').html(jQuery(this).val());
    });
    jQuery('#inPhone').keyup(function(){
        jQuery('#phoneText').html(jQuery(this).val());
    });
    
    • 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 form with three text inputs, one each for Work Phone,
I have a form with a select box and three text input boxes. When
In VB.net 3.5 SP1 I have a Windows Form with three DataGridView controls. One
I have a FormHandler which requires three dependencie-injections: Form, Request and ArticleManager I configured
I have a form where there are 6 items, each of which can be
I have an application in which there is a form which I want to
I have a form in which there are many textBoxes from which three textboxes
Ok so i have a form that has three input boxes, at the moment
I have a C# form with multiple text boxes. Before proceeding I need to
I have a form with a few text-boxes and a Grid-view. There is this

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.