How to Use Both SRC and Inline in JavaScript
- 1). Create a new HTML document using Notepad or any text editor. Include a skeleton HTML outline in the document. For example, type:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Including JavaScript</title>
</head>
<body>
</body>
</html> - 2). Insert a link to an external file containing JavaScript code between the HTML <head> tags using the <script> tag and "src" attribute in the following manner:
<head>
<script type="text/javascript" src="http://mysite.com/jslib/utilities.js"></script>
</head>
Change "mysite.com" to your website and change the name of the external file containing the Javascript code to your own source file. - 3). Open a <script> tag and insert JavaScript code directly into the body of the HTML document where you want the code to execute inline. This code is placed between the document's <body> tags, along with the other content making up the page. For example:
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
You can have several or more blocks of inline Javascript code embedded in several parts of your HTML document by inserting the code as needed.