The following works perfectly fine...displays an alert every 10 seconds
<script type='text/javascript'>
function letsTest(){
alert("it works");
}
var uptimeId = window.setInterval(letsTest, 10000);
</script>
But when I place my letsTest
function in a file called javaScript.js, it no longer works.
main page:
<script src='lib/javaScript.js' type='text/javascript'>
var uptimeId = window.setInterval(letsTest, 10000);
</script>
javaScript.js
function letsTest(){
alert("it works");
}
I verified a thousand times over the path and spelling. I use my javaScript.js
in other places as well. Is it possible to set an interval with a function from another file?
The following works perfectly fine...displays an alert every 10 seconds
<script type='text/javascript'>
function letsTest(){
alert("it works");
}
var uptimeId = window.setInterval(letsTest, 10000);
</script>
But when I place my letsTest
function in a file called javaScript.js, it no longer works.
main page:
<script src='lib/javaScript.js' type='text/javascript'>
var uptimeId = window.setInterval(letsTest, 10000);
</script>
javaScript.js
function letsTest(){
alert("it works");
}
I verified a thousand times over the path and spelling. I use my javaScript.js
in other places as well. Is it possible to set an interval with a function from another file?
2 Answers
Reset to default 13<script src='lib/javsScript.js' type='text/javascript'>
var uptimeId = window.setInterval(letsTest, 10000);
</script>
You cannot provide both a src
and a body for a <script>
tag. One or the other.
You'll have to use two <script>
tags:
<script src='lib/javaScript.js'></script>
<script>
var uptimeId = setInterval(letsTest, 10000);
</script>
Actually the reason behind it may be ,that the variable uptimeId is not accessible inside the file javascript.js. Please let me know if I am wrong.