You are binding the event handler inline in HTML also you are using jQuery to bind again inside the function which is not correct.

Just remove the inline onclick,

<input type="button" id="ImageHosting" value="To Image Hosting" />

And change JS

$(document).ready ( function () {
    $("#ImageHosting").click(function () {
       alert("test");
    });
});

Incase if this button is inserted dynamically then,

$(document).ready ( function () {
    //replace document below with enclosing container but below will work too
    $(document).on('click', "#ImageHosting", function () {
       alert("test");
    });
});

Use .live/.delegate if you older version of jQuery ( < 1.7)

Answer from Selvakumar Arumugam on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ tryit.asp
W3Schools Tryit Editor - JavaScript Alert
The W3Schools online code editor allows you to edit code and view the result in your browser
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ javascript-create-an-alert-on-clicking-an-html-button
JavaScript - Create an alert on clicking an HTML button
March 11, 2025 - <!DOCTYPE html> <html lang="en"> ... (event) { alert("You have pressed the button..........") }) </script> </html> ... Whenever you press the button, you will get an alert message....
๐ŸŒ
IncludeHelp
includehelp.com โ€บ code-snippets โ€บ display-alert-message-on-button-click-event.aspx
Display Alert Message on Button Click Event using JavaScript
HTML and JavaScript: <!--Display Alert Message on Button Click Event.--> <html> <head> <title>Display Alert Message on Button Click Event.</title> <script type="text/javascript"> function showMessage() { alert("Hello friends, this is message."); } </script> </head> <body> <center> <h1>Display ...
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 512d28a06918338f2300e9ea
How to make a html button clickable and to show alert on it ? | Codecademy
<script> function clickAlert() { alert("Alert!"); } </script> <input type="button" onclick="clickAlert()" value="Click-2-Alert"> ... May be it will help youโ€ฆ. <head> <script type="text/javascript"> function conf() { var con=confirm("Do you ...
๐ŸŒ
University of Washington
washington.edu โ€บ accesscomputing โ€บ webd2 โ€บ student โ€บ unit5 โ€บ module2 โ€บ lesson1.html
Lesson 1: Using JavaScript to Show an Alert
The button includes the onclick attribute, which causes the showAlert() to be called when a user clicks the button. The onclick event also works for keyboard users. If a user navigates to the button using the tab key, then presses enter, that too will trigger the alert.
Find elsewhere
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ javascript tutorial โ€บ javascript onclick alert
JavaScript onclick Alert | How does JavaScript onclick Alert work?
October 18, 2022 - We have created the onclick() function and alert() function on same program the html tag elements like button etc will used to create and designed for html web pages and it will call the JavaScript functions for authentication or validation purpose.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Indiana
info.sice.indiana.edu โ€บ ~hrosenba โ€บ Demo โ€บ javascript โ€บ 6alert.html
Alert and Confirm
In the examples where the code is triggered by a button click, the entire code must by contained in quotation marks: onClick="alert( 'Your Message Here...' )" Without the "onClick" syntax, the outside quotation marks are unnecesssary and will cause an error so they should be left out: alert( ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 66790588 โ€บ alert-message-on-button-submit-javascript
html - alert message on button submit javascript - Stack Overflow
function myFunction() { alert("message successfully sent").then(response => { window.location.href = 'index.html'; }) } <div class="col-lg-12"> <input type="submit" class="btn btn-defeault btn-send" value="Send message" onclick="myFunction()"> ...
๐ŸŒ
Bootstrap
getbootstrap.com โ€บ docs โ€บ 4.0 โ€บ components โ€บ alerts
Alerts ยท Bootstrap
Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages. Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the eight required contextual classes (e.g., .alert-success).
๐ŸŒ
CodePel
codepel.com โ€บ home โ€บ html & css โ€บ alert message in html on button click
Alert Message in HTML on Button Click โ€” CodePel
January 27, 2024 - Here is a free Alert Message in HTML on Button Click , source code with preview. You can view demo online & download code.
Call ย  +923061364493
Address ย  Rafi Qamar Road, Al-Majeed Peradise Al Majeed Peradise, 62300, Bahawalpur
Top answer
1 of 4
2

here you have what you needed (http://jsfiddle.net/2v2C2/2/)

// when one of buttons clicked this func will execute
function buttonClick (e) {

    var input = e.target;

    // alert different message for different buttons
        switch(input.getAttribute('id')) {
            case "english":
            alert("Hello! How are you?");
            break;
            case "spanish":
            alert("Hola! Como estas?");
            break;
            case "hebrew":
            alert("Shalom!");
            break;
            case "frech":
            alert("Bonjour!");
            break;
            default:
            alert("Unexpected button pressed ...i don't know what to say");
        }
}


//store buttons in variable buttonsList
var buttonsList = document.getElementsByTagName("input");

//iterate through all elements of buttonList and attach event handler if they are buttons (not all input elements are buttons)
for (var i = 0; i<buttonsList.length; i++) {
    var input=buttonsList[i];
    if (input.getAttribute('type')=='button') {
        input.onclick = buttonClick;
    }
}

2 of 4
1

I saw your problem and found a simple solution for you as you are new in programming.So Please read care fully you will understand everything.As below example,you want to get which button is clicked and according to that you want to alert different message.You can do this easily with jQuery.

See your desired result here http://jsfiddle.net/q6QLy/26/

<body>
    <ul style="list-style-type:none" id="buttons">
        <li>
            <input type="button" value="English" id="english" />
        </li>
        <li>
            <input type="button" value="Spanish" id="spanish" />
        </li>
        <li>
            <input type="button" value="Hebrew" id="hebrew" />
        </li>
        <li>
            <input type="button" value="French" id="frech" />
        </li>
    </ul>
    </body>

    $(document).ready(function() {
       $('input:button').click(function() {
          var buttons = $(this).val();
          alert("You have clicked on button "+buttons);
          switch(buttons){
             case "English":
                 alert("Hello ,how are you ?");
             break;
             case "Spanish":
                 alert("Hola! Como estas?");
                 break;
             case "Hebrew":
                 alert("Shalom!");
                 break;
             case "French":
                 alert("Bonjour!");
                break;
             default:
                 alert("Please select a language");
         }
       });
   });

and also you want to get clicked input type is button then you can use same

var buttonsList = document.getElementsByTagName("input");
  for (var i = 0; i<buttonsList.length; i++) {
    var input=buttonsList[i];
    if (input.getAttribute('type')=='button') {
        //write your function whatever you want.
    }
}
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ javascript-how-to-get-an-alert-to-appear-when-i-click-on-a-button-in-a-class
JavaScript how to get an alert to appear when I click on a button in a class?
October 4, 2024 - <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initialscale=1.0"> <title>Document</title> </head> <body> <button class="clickTheButton">Click to get an alert</button> <script> for (var clickButton of document.getElementsByClassName("clickTheButton")) clickButton.addEventListener("click", alertMeessage); function alertMeessage() { alert("You have clicked the button"); } </script> </body> </html>
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ jquery โ€บ how-to-set-alert-message-on-button-click-in-jquery
How to set alert message on button click in jQuery ? - GeeksforGeeks
September 23, 2024 - The click() event on the button displays the alert message: "This is an alert message!" when clicked. ... <!DOCTYPE html> <html lang="en"> <head> <script src= "https://code.jquery.com/jquery-3.6.0.min.js" integrity= "sha256-/xUj+3OJU5yExlq6...