0

I have a meteor app with a <button>. The button has an onclick event on it that calls a function verifypwd(). My function is declared in a file named verifypwd.js which is in the main directory of the app. When I click my button, it tells me it can't find the function. What's wrong?

Here's my code:

HTML

<head>
  <title>KinnockPass</title>
  <script src="verifypwd.js"></script>
</head>

<body>
</body>

<template name="PPRO">
  <div class="vertibox">
    <div id="authorization-box">
      <div id="authorization">
         <h1>Are you a Riley?</h1>
         <input id="password" type="password"/>
         <button id="password-submit" onclick="verifypwd();">Yes, I Am.</button>
       </div>
     </div>
   </div>
 </template>

 <template name="passed">
 </template>

Main JS File

//Define Route of PPRO Template
Router.route('/', {template: 'PPRO'});
Router.route('/passed');

pwd = new Mongo.Collection("pwd");

verifypwd.js

var verifypwd = function(){
  console.log("Hello");
}
Isaac Wasserman
  • 1,461
  • 4
  • 19
  • 39

1 Answers1

1

Meteor wraps all functions so that their scope is restricted to the file they are in unless they are defined as global functions. If you remove var from var verifypwd it should work. A more meteoric way of doing what you're trying to do is to define a template event for your PPRO template and put your verifypwd code in the same file, then it can be a local function.

Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
  • 1
    All of this is correct. I'd add that the literal answer to his question is that the file isn't loading because it isn't being served from `/public`. – David Weldon Aug 10 '15 at 21:17
  • True, one can put function definitions in public as well. Of course that would lead to the question of why are you verifying a password on the client which I should have asked earlier. – Michel Floyd Aug 10 '15 at 21:37