Onclick event for disabled checkbox?

Discussion in 'JavaScript' started by Alfahane, Apr 14, 2008.

  1. #1
    I want a simple onclick alert on a disabled checkbox:

    <input type="checkbox" name="myBox" id="myBox" value="my value" disabled onclick="alert('This checkbox is disabled because..');" >

    It seem though that a disabled checkbod does not respond to events. The onclick works perfectly on the TD that the input is in.

    Creating an image representation of a checkbox is not an option since I'll need this function for select as well.

    Any ideas?
     
    Alfahane, Apr 14, 2008 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Instead of disabling it, you could inhibit it:

    <input type='checkbox' onclick="if(this.checked && !somethingDone){this.checked=false;alert('You haven\'t finished something yet')}">
    
    Code (markup):
     
    Logic Ali, Apr 14, 2008 IP
  3. Alfahane

    Alfahane Guest

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, so events are indeed disabled for form objects that are disabled?

    The thing is that I thought that only changing values was disabled.
     
    Alfahane, Apr 14, 2008 IP
  4. mixa_ru

    mixa_ru Member

    Messages:
    22
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    38
    #4
    hi!
    Read here: http://stackoverflow.com/questions/7833854/jquery-detect-click-on-disabled-submit-button
     
    mixa_ru, Apr 7, 2016 IP
  5. Bitpalace

    Bitpalace Greenhorn

    Messages:
    53
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    13
    #5
    Bitpalace, Apr 7, 2016 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Honestly, if whatever text explaining why it's disabled is that important, why the blazes isn't it in the label? Skip the scripttard BS altogether.
     
    deathshadow, Apr 11, 2016 IP