I want to get all the values of the radio type input to then compare it with a variable with a set value and if some of those radio type input matches the value of that variable I select that radio type input
I've been trying to get the amount of radio type input that have the same class and then show in an alert the value of those inputs to then compare them with the value of a variable but only shows me the value of the first input. Can someone help me?
How can I do that when a value of all those radios is equal to the value var zone="B3"; activate?
- I was able to make it activate the radio with the indicated value Use the example of KIKO_L and I put this in place of the alert: $ (this) .attr ('checked', true);
var zona = "B3";
$(".zona").each(function() {
if($(this).val() === zona)
{
$(this).attr('checked', true);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="" id="modalAddPermiso" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="examplehttps://es.stackoverflow.com/posts/159707/edit#ModalLabel">Asignación de Permisos por Paginas</h5>
</div>
<div class="modal-body">
<form id="form_permiso" action="" method="POST">
<div class="form-group">
<table class="table table-striped table-condensed">
<label for="Zona">Zona</label>
<tbody>
<tr>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="A1" >A1
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="A2">A2
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="A3" >A3
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="A4" >A4
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="A5" >A5
</label>
</td>
</tr>
<tr>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="B1" >B1
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="B2">B2
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="B3" >B3
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="B4" >B4
</label>
</td>
<td>
<label for="" class="radio-inline">
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="B5" >B5
</label>
</td>
</tr>
<tr>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="C1" >C1
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="C2">C2
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="C3" >C3
</label>
</td>
<td>
<label for="" class="radio-inline">
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonahttps://es.stackoverflow.com/posts/159707/edit#E" id="zonaE" value="C4" >C4
</label>
</td>
<td>
<label for="" class="radio-inline">
<input type="radio" class="zona" name="zonaE" id="zonaE" value="C5" >C5
</label>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancelar</button>
<button type="button" class="btn btn-primary pull-left" id="btnsavepermiso">Guardar</button>
</div>
</div>
</div>
</div>
</body>
</html>