0

I'm trying to find a solution to an issue I have between click and change. I need to capture the click event and not change. I'll explain the situation:

I have a radio button list with 3 items. Each click I need to clean a div. However, If i'm posting back and return to the client with an error(submit, server validation check failed), the change event is fired once again (obviously), and the div is cleaned.

Is there a way to distinguish between click and the checked state?

I hope I have made myself clear. Edit: Added some code:

$("input[name*='SelectedOwner']").on('change',
function () {
    var radioId = $(this).val();
    if (radioId === "2" || radioId === "3") {
        $("#div1").hide();
        $("#divclean :input").removeAttr("disabled");
    } else {
        $("#div1").show();
        $("#divclean :input").attr("disabled", true);
    }
});
$("input[name*='SelectedOwner']").on('click', function () {
   //Clean the output at each change
   $("#divclean :input").val("");
});

Thanks.

Erez Savir
  • 74
  • 1
  • 8

2 Answers2

1

 $('input[name="choose"]').click(function(e) {
   if ($(this).data('clicked')) {
    $('#theDiv').text('You have REclicked "'+ $(this).val() + '" value');
   }
   else {
    $('input[name="choose"]').data('clicked', false);
    $(this).data('clicked', true);
    $('#theDiv').text('First time you click "'+ $(this).val() + '" value');
   }
 })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  
  <div id="theDiv"></div>
  
  A
  <input type="radio" name="choose" value="a" />
  
  B
  <input type="radio" name="choose" value="b" />
  
  C
  <input type="radio" name="choose" value="c" />
Laurianti
  • 903
  • 1
  • 5
  • 19
0

You should to bind the change event to every radio button:

$("#r1, #r2, #r3").change(function () { }

With jQuery is also possible:

if ($("#r1").is(":checked")) {}

More informations: JQuery $(#radioButton).change(...) not firing during de-selection


I hope this helps...

Good Luck!

Community
  • 1
  • 1
ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58