wOlVeRiNe wOlVeRiNe - 1 month ago 7
HTML Question

Accesing variables declared in JAVASCRIPT in a different HTML FILE

I have two files screen.html and db_fun.js.
I have declared a variable at just the beginning as follows:



db_fun.js

var name = "abc";


now i tried to access this variable in the screen.html file as follows


screen.html



<html>
<body>
<form name = "screen" action = "db_fun.js">
<p> <script>document.write(name);</script> </p>
</form>
</body>
<script src="db_fun.js" type="text/javascript" />
</html>


it doesn't print nethn. Y so?

Answer

add this to the head

<script type="text/javascript" src="db_fun.js"></script>