0

I have an input button, which when it is disabled, and someone tries to click it, needs to display an alert.

How is it possible to display a javascript message despite being disabled?

Tried this with no luck:

<input type="submit" onclick="alert('click')" value="Disabled Input Button" disabled/>

MRC
  • 555
  • 2
  • 10
  • 30
  • See this: http://stackoverflow.com/a/7834293/3751213, however you may use `mousedown` event... – j809 Jul 15 '14 at 14:18
  • Possible duplicate of http://stackoverflow.com/questions/7833854/jquery-detect-click-on-disabled-submit-button – Chris Lam Jul 15 '14 at 14:24

2 Answers2

4

Use onmousedown instead of onclick, which is only fired when it is 'allowed' to. Some browsers, particularly Chrome, appear to disable all DOM events when a form element is disabled. While I think this is out of spec, you can use the following workaround:

Instead of using the disabled attribute, use CSS pointer-events to achieve a similar effect, illustrated here:

button.disabled {
    pointer-events:none;    
}

And then just use <button class="disabled"> instead of <button disabled>.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
3
<span  onclick="alert('This input is disabled')">
    <input type="submit" value="Disabled Input Button" disabled/>
</span>

Wrapping it with another tag that has the on click function works.

MRC
  • 555
  • 2
  • 10
  • 30