can more than one function be added in an external javascript file? i.e .js file? [closed]


I tried to write more that one function in an external .js file and it was not working. So i wrote the javascript inside the html body by using tag. cant we write more than 1 function outside? coz only the 1st function used to work well. Where as the rest did not work. I'm a fresher


Yes you can write multiple function into external java script file.i am posting here one small sample. 1. create test.js file inside one folder named as js 2. create test.html file

<strong>1. test.html</strong>

insert following line into test.html file

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript" src="js/test.js"></script> </head> <body> <a href="#" onclick="test()">Click Here to call first function</a><br> <a href="#" onclick="test1()">Click Here to call second function</a> </body> </html> <ol><li>test.js</li> </ol>

Insert following code into your external java script file which name is test.js

function test(){ alert("fist function is called"); } function test1(){ alert("second function is called"); }


  • Calling a function from one JavaScript file which requires another
  • MapBox - Cluster Zooming
  • Calling a JavaScript object class that's in a separate .js file
  • MVC3 - Conditionally add id element with Razor
  • Attaching a file to an iCalendar
  • How to bypass Mechanize “AmbiguityError” in Python
  • PHP Session check not working when i redirect from another page
  • Dynamic Event Handler not Firing
  • :hover CSS is not working?
  • What products support 3-digit region subtags, e.g., es-419 for Latin-American Spanish?
  • Why is this button causing my layout to break?
  • What is the best way to include a style sheet for a specific page?
  • How do I include screenshots of the full page in my serenity report (and not only of the viewport) u
  • ng-repeat not working with table but works with list
  • How do i disable a text box within an iframe
  • Outputting SharePoint Hyperlink Column as URL
  • In matplotlib, how do you change the fontsize of a single figure?
  • CERN ROOT exporting data to plain text
  • Android application: how to use the camera and grab the image bytes?
  • Django simple Captcha “No module named fields” error
  • htaccess add www if not subdomain, if subdomain remove www
  • JSON response opens as a file, but I can't access it with JavaScript
  • Why does access(2) check for real and not effective UID?
  • How to clear text inside text field when radio button is select
  • Scrapy recursive link crawler
  • Paperclip, set path outside of rails root folder
  • Using $this when not in object context
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • Uncaught Error: Could not find module `ember-load-initializers`
  • Accessing IRQ description array within a module and displaying action names
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • Append folder name and increment by 1 using batch script
  • Programmatically clearing map cache