1

I'm trying to write a program that allows the user to enter any word and then press the button to get the result.

The result is "hello".

Can anyone help me to figure out why the result doesn't appear when I render it?

   <head>
      <meta charset = "utf-8">
      <script>
          function start() { 
              var button = document.getElementById("add" );
              button.addEventListener( "click", t, false );
          }

          function t() {  
             r.innerHTML = "Hello";
             window.addEventListener( "load", start, false );
          }         
      </script>     
   </head>

Please help if you know what is wrong in my code.

3
  • This is not written in standard JavaScript. Commented Apr 17, 2013 at 20:56
  • ... or standard HTML, for that matter ;-) Commented Apr 17, 2013 at 20:57
  • 1
    This looks like reasonably normal HTML and JavaScript to me... Not sure what you two are on about. Commented Apr 17, 2013 at 21:08

1 Answer 1

6

Is that your entire code? I don't see a call to start()

Your current call embedded in F1 needs to be moved out of the function into the main code so that it runs when the page is loaded:

window.addEventListener( "load", start, false );

function start()
...

Demo: http://jsfiddle.net/uU2K7/

Sign up to request clarification or add additional context in comments.

1 Comment

The real problem is that there is a call to start embedded in F1 (window.addEventListener( "load", start, false );) which needs to be moved outside of the function call: jsfiddle.net/uU2K7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.