0
$(".dist_radio").click(function(event) {
        event.preventDefault();
        $(".dist_radio").removeClass('dist_on');
        $(".dist_radio").children('input').attr('checked', false);
        $(this).addClass('dist_on');
        $(this).children('input').attr("checked", true);
    });

is the way I'm handling custom styled radio buttons and everything is fine if I click on a single radio (#1) and submit the form - it's being sent without errors (note that I'm having my form submit in a new window), if I chose another radio button (#2) and submit the form - again, the given radio is being sent with no issues, but if I then click back on the previously submitted radio button (#1), I get a validation error that I haven't chosen any radio button even though by checking the element with firebug, I can see that it has checked="checked" set.

Why is that and what can I do to fix it?

Xeen
  • 6,955
  • 16
  • 60
  • 111

3 Answers3

1

Use .prop() instead of .attr() for property values

$(".dist_radio").click(function(event) {
    event.preventDefault();
    $(".dist_radio").removeClass('dist_on');
    $(".dist_radio").children('input').prop('checked', false);
    $(this).addClass('dist_on');
    $(this).children('input').prop("checked", true);
});
Anton
  • 32,245
  • 5
  • 44
  • 54
0

The transition from one slide to the next is handled by your submitHandler, so the radio buttons need to do is submit the form on click, with that in mind:

$('input[type=radio]').click(function() {
    $(this).closest("form").submit();
});
Reshma
  • 1
  • 1
0

Stumbled along with this issue and spent hours solving it. This is why:

.prop() vs .attr()

  • Better to post the content as an answer here. Links might be 404 in the future. Provide the link only as a reference. – Ethan Yang Nov 09 '17 at 04:34