Page 180 - Web_Application_v2.0_C12_Fb
P. 180
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.
Note that type attribute indicates the type of script represented. If not specified, then browser
assumes it is JavaScript.
Step 2: Use the alert() method to display virtual alert box that contains some specified message and
an OK button.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE> My First JavaScript </TITLE>
<SCRIPT>
alert("Hello! This is an internal JavaScript example.");
</SCRIPT>
</HEAD>
<BODY>
<! -- This message box is displayed using JavaScript. -->
</BODY>
</HTML>
178 Touchpad Web Applications (Ver. 2.0)-XII

