If Load javascript

0

I have a following script. There are two checkboxes that will work like two radios buttons, what happens to me, when I click on a checkbox it disables all the questions of the form and also disables the checkbox that was not selected, and when I save my form and I go back in it, the checkbox that I selected is clicked normal, plus all questions on my form are not disabled. Could you help me?

$(document).ready(function() {
  Eventos();

  $('[name="dtd1nrob"]').change(function() {
    verificaCamposExibirOcultar4();
  });

  $('[name="dtd1nrob"]').change(function() {
    verificaCamposExibirOcultar5();
  });
});

function Eventos() {
  verificaCamposExibirOcultar4();
  verificaCamposExibirOcultar5();
};

function verificaCamposExibirOcultar4() {
  var value = $('[name="dtd1nrob"]:checked').val();
  if (value == '1') {
    $('#dtd1nrob2').prop('disabled', true).attr('disabled');
  } else {
    $('#dtd1nrob2').prop('disabled', false).attr('disabled');
  }
}

function verificaCamposExibirOcultar5() {
  var value = $('[name="dtd1nrob"]:checked').val();
  if (value == '2') {
    $('#dtd1nrob1').prop('disabled', true).attr('disabled');
  } else {
    $('#dtd1nrob1').prop('disabled', false).attr('disabled');
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="row">
  <div class="form-group">
    <div class="col-lg-12">
      <div class="col-lg-12">
        <div class="checkbox">
          <label>
            <input type="checkbox" id="dtd1nrob1" checked="@(Model.dtd1nrob == "1" ? true : false)" name="dtd1nrob" value="1">Não realizada por óbito em data anterior</label>
        </div>
      </div>
      <div class="col-lg-12">
        <div class="checkbox">
          <label>
            <input type="checkbox" id="dtd1nrob2" checked="@(Model.dtd1nrob == "2" ? true : false)" name="dtd1nrob" value="2">Não realizada por outro motivo</label>
        </div>
      </div>
    </div>
  </div>
</div>
    
asked by anonymous 07.03.2017 / 14:37

1 answer

0
$(document).ready(function () {
    verificarCheckbox();
    $('[name="dtd1nrob"]').change(function () {
        verificarCheckbox();
    });
});

function verificarCheckbox() {
    $(".todosOsOutrosElementos").show();
    $('[name="dtd1nrob"]').prop('disabled', false).attr('disabled')

    if ($("#dtd1nrob1").is(":checked"))
        $('#dtd1nrob2').prop('disabled', true).attr('disabled');
    else if ($("#dtd1nrob2").is(":checked"))
        $('#dtd1nrob1').prop('disabled', true).attr('disabled');

    if ($('[name="dtd1nrob"]').is(":checked"))
        $(".todosOsOutrosElementos").hide();
}

Replace: $ ("all otherOtherElements"). show () / hide () by its elements.

    
07.03.2017 / 15:12