Return of a Checkbox to Javascript

Asked

Viewed 46 times

0

I need some help, I looked at the posts before a similar subject, but I couldn’t find an example like mine, if you can help me, thank you.

I have an Edit View that already brings the registered value of a checkbox.

<div class="col-md-1 ">
     Aprovado
     @Html.CheckBoxFor(model => model.Aprovado, new {Attributes = new { @class = 
     "form-control" ,  @style = "font-size:12px;", @id = "aprovado", 
     @name="aprovado"} })
</div>

I have a finish button that sends the data for recording, only the checkbox does not work, I tried to debug but presents as undefined.

    $("#finalizar").click(function () {

        alert($("#aprovado").val());
    }

2 answers

0

You get nothing because the checkbox does not have the attribute value, only class, name, id and style.

If you want to receive the "approved" value, include the attribute @value = "aprovado" in the element. Perhaps you should have thought that the @name="aprovado" is what would be sent in the form, but not. What are sent are the values of the elements, not the Names.

0

A way for you to check if the checkbox is checked:

$('#aprovado').prop('checked');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.