Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:14:52+00:00 2026-06-07T00:14:52+00:00

I am a js newbie and I’m trying to grasp inline vs. traditional registration.

  • 0

I am a js newbie and I’m trying to grasp inline vs. traditional registration. Code block 1 (inline) works fine, but code block 2 (traditional) does not. Can anyone shed light on my error?

<html>
<head>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script>
<script>
function gethash() {
var name=prompt("Please enter your name","Harry Potter");
var hash = CryptoJS.MD5(name);
alert("Hello, " + name +".\nYour hash is " + hash)
}
</script>
</head>
<body>
<input type="button" onclick="gethash()" value="Get your hash" />
</body>
</html>

This attempt to use traditional registration does not work:

<html>
<head>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script>
<script type="text/javascript">
function gethash() {
var name=prompt("Please enter your name","Harry Potter");
var hash = CryptoJS.MD5(name);
alert("Hello, " + name +".\nYour hash is " + hash)
}
document.getElementById('myname').onclick = gethash;
</script>
</head>
<body>
<input type="button" value="Get your hash" id="myname" />
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:14:54+00:00Added an answer on June 7, 2026 at 12:14 am

    There is no such element at the point where you’re trying to bind something using onclick. Move that line to the bottom of the file.

    If you look at the console, you should see an error like:

    Uncaught TypeError: Cannot set property ‘onclick’ of null

    This should fix it:

    <html>
    <head>
    <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script>
    </head>
    <body>
    <input type="button" value="Get your hash" id="myname" />
    
    <script type="text/javascript">
    function gethash() {
    var name=prompt("Please enter your name","Harry Potter");
    var hash = CryptoJS.MD5(name);
    alert("Hello, " + name +".\nYour hash is " + hash)
    }
    document.getElementById('myname').onclick = gethash;
    </script>
    
    </body>
    </html>
    

    That leads us to the better way of doing this. Using window.onload, you can execute the JS code after everything has loaded.

    window.onload = function() {
        document.getElementById('myname').onclick = gethash;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question since I'm not up to speed using maven at all. I'm trying
Newbie here with a frustrating, but probably simple question. I am trying to write
Newbie at Python and maybe I'm not stating the question right, but how do
Newbie question I know... But can I build apps for Snow Leopard using the
Newbie question but I can't find the answer. On first run my app is
Newbie to C++ but I am a Java programmer. Trying to learn C++ now.
Newbie :( Tweaking my way through tutorials but 36 hours can't figure this one
Newbie :) I am trying to create a picture w/ description portfolio. It works
Newbie question here. I'm trying to teach myself, and sometimes the solo route can
Newbie jquery: does the .css() function alter css properties of an element if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.