title: call javascript function on link click
body: <p>I want to set a cookie value when user clicks on a link.
  I am using the following code:</p>
  
  <pre><code>&lt;script src="http://code.jquery.com/jquery-1.7.2.min.js"&gt;&lt;/script&gt;
  &lt;script src="../../Scripts/jquery.cookie.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
  
          function changeLang(lang) {
              $.cookie('myCulture', lang);
              window.location.reload();
              return false;
          }
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>  &lt;a href="#" onclick="changeLang('da-DK')"&gt;&lt;img src="../../Content/images/danishFlag.png" height="35px" width="35px"/&gt;&lt;/a&gt;
  
    &lt;a href="#" onclick="changeLang('sv-SE')"&gt;&lt;img src="../../Content/images/swedishFlag.png" height="35px" width="35px"/&gt;&lt;/a&gt;
  </code></pre>
  
  <p>It looks like very simple code, but when I click on the link, there is an error in the browser.
  It says.</p>
  
  <pre><code>ReferenceError: changeLang is not defined   
  
  changeLang("da-DK");
  </code></pre>
  
  <p>Where am I doing wrong??</p>