Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

JS innerHTML property

The innerHTML property can be used to write the dynamic html on the html document.

It is used mostly in the web pages to generate the dynamic html such as registration form, comment form, links etc.

Example of innerHTML property

In this example, we are going to create the html form when user clicks on the button.

In this example, we are dynamically writing the html form inside the div name having the id mylocation. We are identifing this position by calling the document.getElementById() method.

  1. <script type=“text/javascript” >
  2. function showcommentform() {
  3. var data=“Name:<input type=’text’ name=’name’><br>Comment:<textarea rows=’5′ cols=’80’></textarea><br><input type=’submit’ value=’comment’>”;
  4. document.getElementById(‘mylocation’).innerHTML=data;
  5.  }
  6. </script>
  7. <form name=“myForm”>
  8. <input type=“button” value=“comment” onclick=“showcommentform()”>
  9. <div id=“mylocation”></div>
  10. </form>

Test it Now

Output of the above example