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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:02:04+00:00 2026-06-15T07:02:04+00:00

I wonder why the following sample code doesn’t work properly: <!DOCTYPE html> <html> <head>

  • 0

I wonder why the following sample code doesn’t work properly:

<!DOCTYPE html>
<html>

    <head>
        <title></title>
        <style type="text/css">
            textarea, iframe {
                display:block;
                width:300px;
                height:100px;
                margin:3px;
                padding:3px;
                border:1px solid #CCC;
            }
        </style>
    </head>

    <body>
        <textarea id="field" onfocus="getFocus();" onblur="loseFocus();">This is some text.</textarea>
        <iframe name="target"></iframe>
        <script>
            var textarea = document.getElementById('field');
            var iframe = window.target.document;

            function displayResult() {
                if (textarea.value) {
                    iframe.open();
                    iframe.write(textarea.value);
                    iframe.close();
                }
                window.setTimeout(displayResult, 10);
            }

            function getFocus() {
                if (textarea.value == textarea.defaultValue) {
                    textarea.value = '';
                }
            }

            function loseFocus() {
                if (textarea.value == '') {
                    textarea.value = textarea.defaultValue;
                }
            }
            displayResult();
        </script>
    </body>

</html>

Demo: http://jsfiddle.net/RainLover/4ksMR/

The iframe content is supposed to get updated in real time — as soon as the textarea content changes by keyboard or mouse. This approach is an alternative to the oninput event. But since oninput isn’t well-supported across different browsers I decided to create a timer to compare the current text field value with its value in 10 milliseconds before.

  • 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-15T07:02:07+00:00Added an answer on June 15, 2026 at 7:02 am

    “Let me give an example: enter a sentence into the text field. Then select/highlight it. Now press the ‘Delete’ button on your keyboard. You won’t see the same thing on the iframe”

    The problem is this line:

    if (textarea.value) {
    

    If textarea is blank, i.e., the .value is an empty string, then the if condition is falsy and the copy to the iframe doesn’t happen. Just remove the if.

    Demo: http://jsfiddle.net/4ksMR/1/

    (Note that this was the only case where I was able to duplicate your problem that changes were not reflected in the iframe.)

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

Sidebar

Related Questions

I just wonder how does html comment tag work with php code. If I
I wonder why the following does not work with Visual studio typedef struct {
I wonder why in the following code, d is not being cons ed into
Consider the following code sample: interface IData { int Count(); } interface IOperations {
wonder whether someone can help me with the following one... I have a struct
I wonder which method among the following three methods is the best to perform
The following script works for me, but I wonder if it could be done
I have the following program. I wonder why it outputs -4 on the following
I wonder whether someone can help me please. I'm using the following script to
I wonder, what library you would choose for the following: I need to be

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.