Hey everyone. (noob warning!)
I have some javascript on a page which I am trying to move to an external js file, rather than be embedded.
My understanding was that the javascript simply had to be placed into a text file and named whatever.js
I've tried a few times but not had any success.
Perhaps someone could point me in the right direction.
________________________________
I've made a simplistic version of my code here, which basically matches vowels and consonants to make a pseudo word.
<p>
<script type="text/javascript">
function createRan(length) {
var type1 = 'bcdfg',
type2 = 'aaaaa',
rand = function(limit) {
return Math.floor(Math.random()*limit);
},
i, word='', length = parseInt(length,10),
type1 = type1.split(''),
type2 = type2.split('');
for (i=0;i<length/2;i++) {
var ran1 = type1[rand(type1.length)],
ran2 = type2[rand(type2.length)];
word += (i===0) ? ran1.toUpperCase() : ran1;
word += i*2<length-1 ? ran2 : '';
}
return word;
}
document.write( createRan(6) );
</script>
<input type="button" value="RELOAD" onClick="window.location.reload()">
</p>
When I put the js into an external file, it doesn't seem to execute automatically.
Thanks for any help here. I'm tearing my hair out.