I am a new JavaScript user. My teacher told me to display my name using javaScript i solvd it using (document.write) command. and then saving it in(.HTML) format.Now my teacher told me to do the above problm using an external .js file. Plz someone help me to solv this problem. My book provides very few infro about .js or external .js.

Recommended Answers

All 3 Replies

try googling "load an external js file". there are loads of examples on the internet.

Ok you wil need to create a flat file and name it as myname.js then save it in the same directory along with your (x)html document.
Here's the code for myname.js:

function printMyName() {
document.write('Your name!'); }

Now incorporate it with your (x)HTML document:

<html>
<head>
<title>Your title</title>
<script type="text/javascript" src="./myname.js"></script>
</head>
<body>
<p><script type="text/javascript">
// Now let's call the function on the external .js

printMyName();</script></p>
</body>
</html>

BimanD, why dont you mark this thread as solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.