0

I have a kanban where the user can change the state or set it as priority I am able to get the id of the step however I am unable to get the checkbox value my checkbox value is always true.

Here is my html (this html repeats several times if there are for exemple 10 task then this code would repeat 10 times.)

    <form method="post">
        <p style="padding:0px;margin:0px">
            <b>Etapa:</b>
            @Html.DropDownListFor(x => lv_task.contrato_etapa_id, new SelectList(lv_task.etapas, "etapa_id", "nombre_etapa"), htmlAttributes: new { @id="drEtapa", @class = "form-control-kanban-popup-dropdown", @required = "required" })
        </p>
        <p style="padding:0px;margin:0px">
            <label class="checkbox-text">
                Prioridad
                @Html.CheckBoxFor(x=>lv_task.contract_details.prioritario)
                <span class="checkmark"></span>
            </label>
        </p>
        <button id="@lv_task.contract_number">Actualizar y cerrar ventanilla</button>
    </form>

Here is my jquery so far

$(document).ready(function () {
    $("button").click(function (e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "/kanban/salvarEstado",
            data: {
                id_etapa: $('#drEtapa').val(),
                prioridad: $('#chkPrioridad').val()
            },
            success: function (result) {
                alert('ok');
            },
            error: function (result) {
                alert('error');
            }
        });
    });
});

My problem is that the following code is always true

 $('#chkPrioridad').val()

I am using the custom checkbox from w3school that can be found here https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_custom_checkbox

the code that changes when checkbox is checked is the following

<span class="checkmark"></span> //NOT CHECKED

<span class="checkmark"> //IS CHECKED
::after
</span>

Any help would be very appreciated thank you.

Junior Cortenbach
  • 530
  • 1
  • 5
  • 22
  • 1
    Does this answer your question? [checkbox is always "on"](https://stackoverflow.com/questions/6602115/checkbox-is-always-on) – Rajesh G Jun 14 '20 at 02:56
  • @RajeshG no it does not I have tried it but it does not work for me as I do not have a normal checkbox I have a costumized checkbox where the only thing that changes is the ::after in the span – Junior Cortenbach Jun 14 '20 at 10:28

1 Answers1

1

I have found the answer using the following code

$("input[name='lv_task.contract_details.prioritario']").is(':checked')

I am able to get true when the checkbox is checked and false when the checkbox is not checked

Junior Cortenbach
  • 530
  • 1
  • 5
  • 22