0

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>
1
  • For jsfiddle specifically, just move your JavaScript code into the JavaScript box. This is the same as adding a <script> tag referencing an external file. Commented Sep 3, 2013 at 3:10

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.