-1

I'm not familiar with HTML and trying to find out how to use Javascript and variables combined with HTML.
I found some related questions at SO, but nevertheless it's not perfectly clear to me.

============= Working example (after contributions from SO-members) ==============

<html>
   <head>
   </head>
   <body>
       <a id="myAnchorUsers">anchorUsers (was complete failure)</a><br><br>

      <button id="myUsers">Users (was not working)</button><br><br>

      <input type="button" value="Users (works !)" onclick="document.location= runUsers;" />

     <script>         
         var runFrom          = "https://script.google.com/macros/s/";
         var runFile          = "AKfycbyql5kQWwZY0eEtN2QtfP-MGN9X3P0sJZsjW9zi3r3";
         var runUsers         = runFrom + runFile + "/exec";

         var btnUsers         = document.getElementById("myUsers");
         btnUsers.href        = runUsers;
         btnUsers.onclick     = function () { document.location= runUsers };

         var ancUsers         = document.getElementById("myAnchorUsers");
         ancUsers.href        = runUsers;

      </script>

   </body>
</html>

So I would like to know what I should do to make all methods work.
Can anybody show how to correct the code above to make it work.

=======================================================================

EDIT

Thanks everybody who contributed (so fast !) to the make it work.
I changed the question to a working example as I've searched before and haven't found a real working example. Other people might benifit from it in future.

The two people who reacted negative to this question (within a few minutes) I would like to say this :

a) Even if a question has been answered somewhere else it is much more helpful to pointto the answer instead of just mentioning 'it has been answered somewhere else'
b) I mentioned already I have been trying to find the answer to make it work BEFORE posting the question.

Thanks for the help!!

SoftwareTester
  • 886
  • 1
  • 9
  • 20

1 Answers1

1

The problem you have here is the <script> element is in the <head>, so it is run before the page is loaded, and the elements you're trying to reference don't exist yet. Move the <script> tag to just before the closing </body> tag.

Dave Morrissey
  • 4,063
  • 1
  • 19
  • 30