javascripthtmlvar

How to declare global var in javascript and HTML?


How to declare a variable, I think global, the way I declare in an html file and then use it in a js file (included by <script> tags)?


Solution

  • So as I understand, you want to use a variable from an HTML file in a JS file? To pass a variable from an HTML file to a javascript file, pass it with a function:

    HTML.html

        <a href="#" onClick="test('John Doe')">Send Name</a>
    

    Javascript.js

    function test(full_name) {
     alert(full_name);
    }