Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 69 - 2609_Logicode
P. 69

    UNDERSTANDING THE <SCRIPT> TAG

                     The <SCRIPT> tag embeds JavaScript or links to external files, adding dynamic features like form
                     validation,  event  handling and animations.  Content  between  the  <SCRIPT> tags  is  treated  as
                     JavaScript or another scripting language.
                     The basic syntax of the <SCRIPT> tag is as follows:

                     <SCRIPT TYPE="text/javascript" SRC="path of the JavaScript file/ File
                     name"></SCRIPT> where,
                       TYPE: This attribute specifies the type of script language. For JavaScript, it’s typically “text/
                       javascript”, but this is optional in HTML5.

                       SRC: This attribute specifies the URL or path of an external JavaScript file to be linked.
                     In an HTML document, JavaScript can be integrated in three distinct places, which are as follows:

                       In the body: The script runs as the page loads and the output appears in the HTML content.
                       In the head (as a function): Scripts are written as functions, which can be called from anywhere
                       else in the page.

                       As an external file: JavaScript code can be written in a separate file with a .js extension. This
                       file is linked to the HTML document using the <SCRIPT> tag.

                               TYPES OF JAVASCRIPT

                     In HTML, you 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.

                     You 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>                                                    <BODY>
                     <SCRIPT>                                                  <SCRIPT>
                     JavaScript code                                           JavaScript code
                                                             OR
                     .....                                                     .....
                     </SCRIPT>                                                 </SCRIPT>
                     </HEAD>                                                   </BODY>

                        Code
                          1      Create a web page to demonstrate the concept of internal JavaScript.

                     <!DOCTYPE HTML>

                     <HTML>

                     <HEAD>

                                                                                               JavaScript for Beginners  67

| 64 65 66 67 68 69 70 71 72 73 74 |