0
I have several checkbox
that will make an ajax call, but only the first checkbox
You make the call.
Any solution in the Ids for this list to make the same call ajax?
Script:
<script>
$(document).ready(function () {
$("#SelectDias").click(function () {
//chamada Ajax
} else {
}
});
});
</script>
Html:
<input type="checkbox" id="SelectDias" name="SelectDias" value="Domingo" class="checkbox-inline" />
@Html.Label("Domingo", new { @class = "control-label" })
<br />
<input type="checkbox" id="SelectDias" name="SelectDias" value="Segunda-Feira" class="checkbox-inline" />
@Html.Label("Segunda-Feira", new { @class = "control-label" })
<br />
<input type="checkbox" id="SelectDias" name="SelectDias" value="Terça-Feira" class="checkbox-inline" />
@Html.Label("Terça-Feira", new { @class = "control-label" })
<br />
<input type="checkbox" id="SelectDias" name="SelectDias" value="Quarta-Feira" class="checkbox-inline" />
@Html.Label("Quarta-Feira", new { @class = "control-label" })
<br />
<input type="checkbox" id="SelectDias" name="SelectDias" value="Quinta-Feira" class="checkbox-inline" />
@Html.Label("Quinta-Feira", new { @class = "control-label" })
<br />
<input type="checkbox" id="SelectDias" name="SelectDias" value="Sexta-Feira" class="checkbox-inline" />
@Html.Label("Sexta-Feira", new { @class = "control-label" })
<br />
<input type="checkbox" id="SelectDias" name="SelectDias" value="Sábado" class="checkbox-inline" />
@Html.Label("Sábado", new { @class = "control-label" })
Perfect, enter the function, I do not understand why in the call ajax always takes the first value of my first checkbox, ie "Sunday".
– Simão Lopes
data: { dayPertendidos: $(".checkbox-inline"). val() }
– Simão Lopes
Simãolopes in this case, use according to Diego’s answer, making a $(this) to catch the element that triggered the event. The context this in the case of events in jQuery is the element that triggers the event (beware of Event Bubbling pranks, but here is not the case).
– Gabriel Katakura
Perfect. Thank you :)
– Simão Lopes