jQuery: why doesn't radio button's change event handler retrigger?

Stefan Dahl

I have a group of radio buttons...

<input type="radio" name="option1" value="foo">
<input type="radio" name="option1" value="bar">

that when checked will use a confirm() to ask if the user really wants to check that radio button or cancel. If user cancels I want the radio button to be unchecked so that user can repeat the same process if necessary:

    $("input [type=radio]").change(function() {
        if(confirm_canceled) {
            $(this).prop("checked", false).trigger('change');
        }
    });

The radio button is unchecked but if I click the radio button again the event handler isn't activated. I guess it's because change() triggers on changes on the value and nothing has changed, so how do I fix this?

edit: issue was a bug caused by using confirm instead of confirm_canceled * face palm *

Drewness

Here is a basic example.

$('input[type=radio]').on('change', function () {
	var checked = confirm('Are you sure?');
  if (!checked) {
    $(this).prop('checked', false);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="option1" value="foo">
<input type="radio" name="option1" value="bar">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Radio button jQuery change doesn't work

From Dev

Checking radio button with jQuery doesn't trigger radio's onclick event

From Dev

Radio Button Change Event Doesn't Fire Properly

From Dev

Jquery prop function doesn't work inside Change event handler

From Dev

Why doesn't my JQuery event handler remove code work

From Dev

Radio button with accordion, radio button selected doesn't change

From Dev

Why doesn't the 'change' event in jQuery fire onChange in ReactJS?

From Dev

Why doesn't the 'change' event in jQuery fire onChange in ReactJS?

From Dev

JQuery Mobile : Radio Button Doesn't Reflect

From Dev

jQuery doesn't respond after change of div content - delegated event handler

From Dev

jQuery Radio Button Change

From Dev

How to apply on change event on radio button using jquery

From Dev

Setting a radio button with .prop() is not triggering event handler

From Dev

Setting a radio button with .prop() is not triggering event handler

From Dev

Backbone radio button change event

From Dev

Backbone radio button change event

From Dev

Why is my jquery .change event only running once on radio buttons?

From Dev

Why won't the change event handler work with my code?

From Dev

jQuery trigger change event doesn't work

From Dev

On Change event doesn't work Jquery

From Dev

Using jQuery to add Event Handler doesn't work

From Dev

Change event fires jquery handler but not javascript handler

From Dev

Why a button inside an UpdatePanel doesn't execute a JQuery event after the first time

From Dev

Why jquery event doesn't handle?

From Dev

Radio Button doesn't reflect Model's value

From Dev

Radio Button doesn't reflect Model's value

From Dev

Why can't I check this radio button using jQuery?

From Dev

Why doesn't jquery call the success handler in this case?

From Dev

Why doesn't the jQuery event ".on" have any event argument

Related Related

  1. 1

    Radio button jQuery change doesn't work

  2. 2

    Checking radio button with jQuery doesn't trigger radio's onclick event

  3. 3

    Radio Button Change Event Doesn't Fire Properly

  4. 4

    Jquery prop function doesn't work inside Change event handler

  5. 5

    Why doesn't my JQuery event handler remove code work

  6. 6

    Radio button with accordion, radio button selected doesn't change

  7. 7

    Why doesn't the 'change' event in jQuery fire onChange in ReactJS?

  8. 8

    Why doesn't the 'change' event in jQuery fire onChange in ReactJS?

  9. 9

    JQuery Mobile : Radio Button Doesn't Reflect

  10. 10

    jQuery doesn't respond after change of div content - delegated event handler

  11. 11

    jQuery Radio Button Change

  12. 12

    How to apply on change event on radio button using jquery

  13. 13

    Setting a radio button with .prop() is not triggering event handler

  14. 14

    Setting a radio button with .prop() is not triggering event handler

  15. 15

    Backbone radio button change event

  16. 16

    Backbone radio button change event

  17. 17

    Why is my jquery .change event only running once on radio buttons?

  18. 18

    Why won't the change event handler work with my code?

  19. 19

    jQuery trigger change event doesn't work

  20. 20

    On Change event doesn't work Jquery

  21. 21

    Using jQuery to add Event Handler doesn't work

  22. 22

    Change event fires jquery handler but not javascript handler

  23. 23

    Why a button inside an UpdatePanel doesn't execute a JQuery event after the first time

  24. 24

    Why jquery event doesn't handle?

  25. 25

    Radio Button doesn't reflect Model's value

  26. 26

    Radio Button doesn't reflect Model's value

  27. 27

    Why can't I check this radio button using jQuery?

  28. 28

    Why doesn't jquery call the success handler in this case?

  29. 29

    Why doesn't the jQuery event ".on" have any event argument

HotTag

Archive