1

If I am using a submit button as so..

<input type="image" name="submit" src="image.png" disabled="disabled" />

Is there any way I can trigger a Javascript alert when someone clicks this button? I have tried using onclick() but it doesn't work unless I take away the disabled="disabled".

1
  • 1
    Whenever I need to do something like this, I create my own buttons using an a tag and then I can style them however I want (rather than using the disabled attribute I would just use a disabled class). I can handle the click with javascript and submit the form that way. It also means I get click event regardless of "disabled" or not Commented Jan 24, 2013 at 16:58

1 Answer 1

6

No, the disabled setting also disables events.

If you need behavior to remain, then instead of disabling it, you should just keep it enabled, and enforce the behavior you want based on some flag added to the element, like a class or some other property on the element.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 you are correct, I didn't realize it used stopPropagation() so the event doesn't bubble up the DOM tree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.