Sunday, 11 September 2016

html - onKeyUp not working javascript




I am trying to populate the div tag with what is typed in the name field (example below) using javascript. I am not sure what I am doing wrong but it is not working and I have at a loss as to why not?
All I want is when the user types their first name it appears below. I have looked at other examples and still confused why this one will not work.



 



hello whirled




Bla Bla





Other Text goes here



Type your first name here:


's ball is not in the ball park.







Answer



You are referencing the element before it is rendered. It is like trying to eat a pizza before you make it.




You need to attach the event after the element is rendered. Either window.onload, document ready, or add the script after the element in the markup.



 



hello whirled




Bla Bla




Other Text goes here



Type your first name here:



's ball is not in the ball park.







No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...