blsn blsn - 1 month ago 12
HTML Question

How to use external ".js" files

I have the following two javascript functions:

1

showCountry()


2

showUser()


I would like to put them in external ".js" files

1

<a href="javascript:showCountry('countryCode')">countryCode</a>


2

<form>
<select name="users" onChange="showUser(this.value)">
<option value="1">Tom</option>
<option value="2">Bob</option>
<option value="3">Joe</option>
</select>
</form>


What is the correct syntax to call these functions?

Answer

Code like this

 <html>
    <head>
          <script type="text/javascript" src="path/to/script.js"></script>
          <!--other script and also external css included over here-->
    </head>
    <body>
        <form>
            <select name="users" onChange="showUser(this.value)">
               <option value="1">Tom</option>
               <option value="2">Bob</option>
               <option value="3">Joe</option>
            </select>
        </form>
    </body>
    </html>

I hope it will help you.... thanks