Wednesday, 4 February 2015

Create an HTML page to print contents of a page body using JavaScript.

Create an HTML page to print contents of a page body using JavaScript.
  1. <html>
  2. <head>
  3. <script>
  4. var selectobj = document.getElementById("select"); 
  5. divtestobj.innerHTML += selectobj.options.length;
  6. function hello()
  7. {
  8. var divtestobj = document.getElementById("divtest");
  9. var selectobj = document.getElementById("select");
  10. if(selectobj.selectedIndex !=0)
  11. {
  12. divtestobj.innerHTML += selectobj.options[selectobj.selectedIndex].value;
  13. }
  14. else
  15. {
  16. alert("You cannot select this value");
  17. }
  18. }
  19. </script>
  20. </head>
  21. <body>
  22. <select id="select">
  23. <option value="0">Select</option>
  24. <option value="One">1</option>
  25. <option value="Two">2</option>
  26. <option value="THREE">3</option>
  27. <option value="FOUR">4</option>
  28. <option value="FIVE">5</option>
  29. </select>
  30. <input type="button" value="Click Me" onclick="hello()" />
  31. <div id="divtest">
  32. </div>
  33. </body>
  34. </html>

No comments:

Post a Comment