user2739569
user2739569

Reputation: 7

How to change my javascript from inline to and external file?

I have this piece of code below it functions exactly how i want it too, I just wanna know how to then move in into another .js file. Sorry I'm new with this.

So what I'm pretty much asking is how to call this code in an html document http://jsfiddle.net/BgWjv/

HTML:

 <select id="selectday">
  <option>Day</option>
  <script>
   var select = document.getElementById("selectday");
   var options = new Array();
   var temp = 1;
   for(var i = 0; i < 31; i++) {
     options.push(temp);
     temp++;
   }
   for(var i = 0; i < options.length; i++) {
     var opt = options[i];
     var el = document.createElement("option");
     el.textContent = opt;
     el.value = opt;
     select.appendChild(el);
   }
 </script>
</select>

Upvotes: 0

Views: 99

Answers (1)

rsp
rsp

Reputation: 111336

It's JavaScript, not Java. And you put everything from between <script> and </script> in a file, like "file.js" and include in in the document using:

<script src="file.js"></script>

Upvotes: 4

Related Questions