7

I know already how to alert by use javascript or Jquery. But just onclick button I apply javascript external or internal. What I need is we alert inline of button Example:

<button name="my_btn" id="my_btn" onClick="alert('Hello I am alert')">Alert</button>

If it is possible please tell me. I am waiting for all of you

Sasidharan
  • 3,676
  • 3
  • 19
  • 37
Bong Yuth
  • 95
  • 1
  • 2
  • 4

4 Answers4

13

I never really understand why someone wants to do it this way, but here is an inline alert on a button.

<button type="button" onclick="alert('Hello World')">Show Alert</button>

Here is the fiddle

By the way, I believe this question has been answered

Did I answer your question?

Community
  • 1
  • 1
j7m
  • 1,067
  • 8
  • 13
  • Thank it is work but before I try it still not work I don't know too but for now I use this it work thank. Oh maybe the browser is catching – Bong Yuth Aug 20 '13 at 09:08
  • Are you sure your browser has Javascript enabled? And are you sure that you don't have any other JS or jQuery functions intercepting this click? Maybe you need to post more code? – j7m Aug 20 '13 at 09:10
  • call like this it should work in all browsers – usman allam Aug 20 '13 at 09:12
  • @BongYuth I guess your `button` is within a `form`. By default many browsers submit the form (which reloads the page) when clicking a `button` without `type` attribute. – Teemu Aug 20 '13 at 09:16
1
<input type='button' onclick="javascript:alert('test');" value='Button'/>
usman allam
  • 274
  • 1
  • 5
0

You can use:

<input type='button' onclick="alert('a');" value='Button'/>
danielb
  • 878
  • 4
  • 10
  • 26
  • Thank it is work but before I try it still not work I don't know too but for now I use this it work thank. Oh maybe the browser is catching – Bong Yuth Aug 20 '13 at 09:07
0

You can use the following snippet to call the alert function from your HTML:

<input type="button" value="click me!" onclick="alert('your message here');" />

But it is generally accepted you should not inline JavaScript and not use alert. You can check this question for more: Flash Message - jQuery

Community
  • 1
  • 1
debel
  • 23
  • 6