Results 1 to 8 of 8

Thread: Displaying typed text

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Displaying typed text

    I have several text boxes on one screen. As those text boxes are being filled in by the user I need to display the values of the text boxes on a different portion of the screen without submitting the form. Is there a way to do this, and if so can you give me some guidance??? I am thinking that it will probably be done in Javascript.

    Thanks to all that reply
    Last edited by mrstuff68; Jul 27th, 2006 at 12:27 PM.

  2. #2
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Re: Displaying typed text

    Javascript would be the way, yes, and pretty much the only way I can think of. Basically you need to grab the textbox value and add it to a string, then add it to the innerHTML or childNode.data of the element that is to display the text.

    Use += to build the string, and you have to call the function onkeyup event. It'll probably slow the typing down some, and it will break the 'undo' function in IE.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Re: Displaying typed text

    Does anyone have an example that I can relate to?

  4. #4
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Re: Displaying typed text

    Well if you check view source on this page, you'll see a function called postLength() which is one I wrote for a feature we did away with. But it has some of the parameters in common with what this one would need to have.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Displaying typed text

    Include this;

    Code:
    var theTextBox;
    var theDisplay;
    
    function doTextKeyUp(e)
    {
      while (!theDisplay.hasChildNodes())
        theDisplay.appendChild(document.createTextNode(''));
    
      theDisplay.firstChild.data = theTextBox.value;
    }
    
    addEHandler(window, 'load', function() {
      theTextBox = document.getElementById('theTextBox');
      theDisplay = document.getElementById('theDisplay');
      addEHandler(theTextBox, 'keyup', doTextKeyUp);
    });
    HTML Code:
    <!-- ... -->
      <input type="text" id="theTextBox">
      <span id="theDisplay"></span>
    <!-- ... -->

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Re: Displaying typed text

    Exactly what I was looking for, thanks!!

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Re: Displaying typed text

    Now I have another question. With the code that penegate has posted. If I have the info for those text boxes coming in from another page, how would I go about calling the code to execute, and check the text boxes onload. If they are blank we are all set, but if we have info coming over they are automatically prepopulated.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Displaying typed text

    If they're already populated when you serve the page just put the same content into the span element.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width