Page 327 - Webapplication11_C11_Flipbook
P. 327

The TYPE attribute of the <SCRIPT> tag is used to specify the language of the script. In this case, we have used the "text/
                 javascript" value. Some other values of the TYPE attribute are "text/css" and "text/vbscript". However, it is optional to
                 use the TYPE attribute in the case of JavaScript as "text/javascript" is the default value of it.
                 In HTML, we can use JavaScript in two ways internally and externally.

                 Internal JavaScript
                 When JavaScript code is written within the HTML web page then it is called internal JavaScript. We use the <SCRIPT>
                 and </SCRIPT> tags to place the JavaScript code either in the <HEAD> or <BODY> tag of the HTML document. The
                 syntax to add internal JavaScript is:

                   <HEAD>
                   <SCRIPT>
                   JavaScript code
                   .....
                   </SCRIPT>
                   <HEAD>
                   OR
                   <BODY>

                   <SCRIPT>
                   JavaScript code
                   .....
                   </SCRIPT>
                   </BODY>
                 Creating a Web Page with Internal JavaScript
                 Similar to HTML web page, we can use any text editor like Notepad, Visual Studio Code, Sublime Text, etc. to create
                 JavaScript programs. After typing the JavaScript code, any web browser like Google Chrome, Firefox, Microsoft Edge,
                 etc. are used to view the web page. Let us create a web page using internal JavaScript.
                 Follow the given steps to create a JavaScript program:

                 Step 1:  Type <script type = “text/JavaScript”> between the <HEAD> and </HEAD> tags to use JavaScript.
                 Step 2:  Use the alert() method to display virtual alert box that contains some specified message and an OK button.
                         <HTML>

                         <HEAD>
                         <TITLE> My First JavaScript </TITLE>
                         <SCRIPT TYPE="text/javascript">
                         alert("Hello World!");
                         </SCRIPT>
                         </HEAD>
                         <BODY>
                         This message box is displayed using JavaScript.

                         </BODY>
                         </HTML>
                 Step 3:  Save the above code with .html extension and then open this file in any web browser. The web browser
                         displays the alert message ‘Hello World’.


                                                                                                  JavaScript Part 1  325
   322   323   324   325   326   327   328   329   330   331   332