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

  • SEARCH
  • Home
  • 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 9077477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:22:32+00:00 2026-06-16T19:22:32+00:00

I am newbie to Javascript, I have difficulties getting the meaning of this code

  • 0

I am newbie to Javascript, I have difficulties getting the meaning of this code properly. I would like to share my thought over the code,and I need your guidance to understand it correctly.

<body>
  <form>
    <input type="button" value="Click Me!" id="say_hi" />
  </form>
  <script type="text/javascript" src="js_event_01.js"></script>
</body>

function hi_and_bye() {
  window.alert('Hi!');
  window.alert('Bye!');
 }
var hi_button = document.getElementById("say_hi");
hi_button.onclick = hi_and_bye;

My understanding: the event “onclick” calls the function “hi_and_bye” when ID is “get_alerts”. Similarly this could be applied to any event, and I can give an id attribute to any element and that id would be responsible to make an accessible corresponding input element.

  • 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-16T19:22:34+00:00Added an answer on June 16, 2026 at 7:22 pm

    Your understanding is correct. You could give an id to any DOM element, not only inputs. Then using the getElementById you could retrieve a reference to this element.

    In this example that’s what you are doing:

    // Get a reference to a DOM element that has id="say_hi"
    var hi_button = document.getElementById("say_hi");
    
    // subscribe to the onclick event handler of the DOM element we retrieved on  
    // the previous line and attach this handler to the hi_and_bye javascript function
    hi_button.onclick = hi_and_bye;
    

    I don’t think that the body of the function itself requires any more explanation: it will just display 2 alerts once after the other when this function executes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im a javascript newbie and would need some help with this simple thing... I
A JavaScript newbie here. I have this following code: function testObject(elem) { this.test =
This is a newbie question: I have a pre-existing function that I would like
Newbie in javascript.. Need a little help. I have a SPAN or IMG that
I have been trying to create a code like this: If you show 'us.gif'
This is a newbie question. I have two javascript and one html files. When
Simple question. I'm newbie on javascript and html. I have a file index.html like:
i need help with a little code that i have below. i'm a newbie
I am a newbie at Javascript and Jquery. I have a form that I
I have some problems with Javascript. In fact, I'm just newbie in that script

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.