0% found this document useful (0 votes)
5 views2 pages

Java Script

The document provides examples of how to use JavaScript within HTML, including placing scripts in the body and head tags, as well as in external files. It explains the use of the document.write() function for dynamic content and the document.getElementById() method for accessing HTML elements by their ID. Additionally, it includes a sample function to calculate the cube of a number entered by the user.

Uploaded by

japneet kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Script

The document provides examples of how to use JavaScript within HTML, including placing scripts in the body and head tags, as well as in external files. It explains the use of the document.write() function for dynamic content and the document.getElementById() method for accessing HTML elements by their ID. Additionally, it includes a sample function to calculate the cube of a number entered by the user.

Uploaded by

japneet kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

<script>
2. document.write("Hello JavaScript by JavaScript");
3. </script>

Places to put JavaScript code


1. Between the body tag of html
2. Between the head tag of html
3. In .js file (external javaScript)
4. <html>
5. <body>
6. <script type="text/javascript">
7. alert("Hello Javatpoint");
8. </script>
9. </body>
10. </html> <html>
11. <head>
12. <script type="text/javascript">
13. function msg(){
14. alert("Hello Javatpoint");
15. }
16. </script>
17. </head>
18. <body>
19. <p>Welcome to Javascript</p>
20. <form>
21. <input type="button" value="click" onclick="msg()"/>
22. </form>
23. </body>
24. </html>
The script tag specifies that we are using JavaScript.

The text/javascript is the content type that provides information to the


browser about the data.

The document.write() function is used to display dynamic content


through JavaScript. We will learn about document object in detail later.

Javascript - document.getElementById()
method
The document.getElementById() method returns the element of specified
id.

1. <script type="text/javascript">
2. function getcube(){
3. var number=document.getElementById("number").value;
4. alert(number*number*number);
5. }
6. </script>
7. <form>
8. Enter No:<input type="text" id="number" name="number"/><br/>
9. <input type="button" value="cube" onclick="getcube()"/>
10. </form>

You might also like