Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 30th, 2015, 12:48 PM   #1
code guy
Newbie
 
Join Date: Dec 2012
Posts: 13
Rep Power: 0 code guy is on a distinguished road
External JavaScript

Hello, I'm currently working on a HTML file where I link an external JavaScript file so that I don't have to keep writing out large functions within the HTML itself. I'm using the <script> tags but when I run the HTML it doesn't seem to be executing the function form the JavaScript, here is a simplified example to demonstrate what I mean:

HTML:

<html>
<head>
<title>Test</title>
</head>

<body>


<h1>This is a test</h1>

// Importing JavaScript file (I've checked that the file path is correct)
<script type="text/javascript" src="LargeFunctions.js">

// Attempting to use a JavaScript function created in the imported file
externalTest();

</script>


</body>

</html>



javascript:


function externalTest()
{
alert("If this message is displayed then the javascript file has been successfully linked to the html");
}


As you can see the externalTest() function should display alert text as soon as I load the web page, but instead it just does nothing, I don't understand why this would be the case, so if anyone could help me out that would be great. Thanks in advance.
code guy is offline   Reply With Quote
Old Jan 31st, 2015, 5:53 AM   #2
pritaeas
mod_pritaeas
 
Join Date: May 2009
Location: The Netherlands
Posts: 251
Rep Power: 9 pritaeas is on a distinguished road
Re: External JavaScript

It's possible/likely that the script is not loaded yet when the browser hits the function call. Try moving your script into the head tag.
pritaeas is offline   Reply With Quote
Reply

Bookmarks

Tags
css, external, html, import, javascript, onclick, script, web application

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
unresolved external symbol __imp__HeapFree cricketlong C++ 2 Dec 19th, 2009 12:11 AM
HTML page not reading external Javascript file aznluvsmc JavaScript and Client-Side Browser Scripting 9 Nov 21st, 2005 10:17 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC