2 Replies - 1207 Views - Last Post: 15 November 2008 - 03:26 PM

#1 Shadow_x21  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 15-September 08

How To Reference A Javascript file in html

Posted 15 November 2008 - 02:18 PM

Shadow_x21

Hi, I just started learning javascript a couple days ago and i was curious from the beggining how to reference a js file in html. I learned How to call the file but im not sure how to access the js file's functions.

simple example :

javascript file -- named hi.js
<script type="text/javascript">

function MsgBox (mine) {
alert (mine) }

</SCRIPT>



html file with a refernce to the js file -- html file named sample.html
(their located in the sme dir)
<html>

<head>
<script type="text/javascript" src="hi.js"></script>
</head>

<BODY> 
<FORM>
<INPUT NAME="text1" TYPE=Text>
<INPUT NAME="submit" TYPE=Button VALUE="Show Me" onclick="MsgBox(form.text1.value)">
</FORM>
</body>

</html>




Any help would be great...Thanks...

Shadow_x21

Is This A Good Question/Topic? 0
  • +

Replies To: How To Reference A Javascript file in html

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4193
  • View blog
  • Posts: 11,868
  • Joined: 18-April 07

Re: How To Reference A Javascript file in html

Posted 15 November 2008 - 02:24 PM

Well once you have included it in the HTML, you can access the javascript functions just like you would if it was inline to the page itself. You can call the functions from javascript events (like onclick, onblur, onchange etc) and you can call it from within <script type="text/javascript"> tags etc.

It would be like you had defined the script tags right in the page itself. :)
Was This Post Helpful? 0
  • +
  • -

#3 Shadow_x21  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 15-September 08

Re: How To Reference A Javascript file in html

Posted 15 November 2008 - 03:26 PM

Thanks Man...
I Figured Out was Wrong Too...

I Was Using The <script></script> tags in the js file. thats what was wrong.

Thanks Anyways...

Shadow_x21
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1