Create an HTML page to print contents of a page body using JavaScript.
- <html>
- <head>
- <script>
- var selectobj = document.getElementById("select");
- divtestobj.innerHTML += selectobj.options.length;
- function hello()
- {
- var divtestobj = document.getElementById("divtest");
- var selectobj = document.getElementById("select");
- if(selectobj.selectedIndex !=0)
- {
- divtestobj.innerHTML += selectobj.options[selectobj.selectedIndex].value;
- }
- else
- {
- alert("You cannot select this value");
- }
- }
- </script>
- </head>
- <body>
- <select id="select">
- <option value="0">Select</option>
- <option value="One">1</option>
- <option value="Two">2</option>
- <option value="THREE">3</option>
- <option value="FOUR">4</option>
- <option value="FIVE">5</option>
- </select>
- <input type="button" value="Click Me" onclick="hello()" />
- <div id="divtest">
- </div>
- </body>
- </html>
No comments:
Post a Comment