
Marcar checkbox mediante un select
Publicado por Daniel (3 intervenciones) el 09/05/2016 21:47:27
Buenaaaas,
Si soy novato en programación, en los apartados de scripts ya ni os cuento... de todas formas he podido adaptar un código a lo que quiero, y como quiero que funcione... bueno, a medias, por eso estoy preguntando ;)
Al lio, estoy montando un sistema de mensajes personales, y me gustaría marcar checkbox a partir de otros checkbox padre... conseguido, eso ya funciona, y además por id del checkbox... muy necesario según mis necesidades.
Ahora quiero marcar algunos checkbox, a partir de las opciones de una lista desplegable o select. Y NO VA BIEN. si probais el código o lo mirais... al final del script, el equipo educativo de primaria de 1ºA lo forman los profesores (prof01), (prof03) y (prof04).
el equipo educativo de primaria de 1ºB lo forman los profesores (prof02), (prof04) y (prof06)
el (prof04) esta en ambos equipos educativos, pero sólo se muestra en la última opción del select... no se marca si elijo el equipo de 1ºA. ¿por qué?
el código es mas extenso, pero aquí esta algo simplificado, espero haberme hecho entender...
Un saludo
Si soy novato en programación, en los apartados de scripts ya ni os cuento... de todas formas he podido adaptar un código a lo que quiero, y como quiero que funcione... bueno, a medias, por eso estoy preguntando ;)
Al lio, estoy montando un sistema de mensajes personales, y me gustaría marcar checkbox a partir de otros checkbox padre... conseguido, eso ya funciona, y además por id del checkbox... muy necesario según mis necesidades.
Ahora quiero marcar algunos checkbox, a partir de las opciones de una lista desplegable o select. Y NO VA BIEN. si probais el código o lo mirais... al final del script, el equipo educativo de primaria de 1ºA lo forman los profesores (prof01), (prof03) y (prof04).
el equipo educativo de primaria de 1ºB lo forman los profesores (prof02), (prof04) y (prof06)
el (prof04) esta en ambos equipos educativos, pero sólo se muestra en la última opción del select... no se marca si elijo el equipo de 1ºA. ¿por qué?
el código es mas extenso, pero aquí esta algo simplificado, espero haberme hecho entender...
Un saludo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<table width="50%" border="0">
<tbody>
<tr>
<td><input id="checkclaustro" type="checkbox" /> TODOS/NINGUNO</td>
</tr>
<tr>
<td><input id="checkprimaria" type="checkbox" /> PRIMARIA</td>
</tr>
<tr>
<td><input id="checksecundaria" type="checkbox" /> SECUNDARIA</td>
</tr>
</tbody>
</table>
<p> </p>
<select name="equipos_ed" id="equipos">
<option value="selecciona">Selecciona un Equipo Educativo</option>
<option value="prim_1a">1ºA Primaria</option>
<option value="prim_1b">1ºB Primaria</option>
</select>
<p> </p>
<table width="100%" border="0">
<tbody>
<tr>
<td><input name= "checkprof[]" value="Ana Perez Garrido" id="prof01" type="checkbox" /> Perez Garrido, Ana</td>
<td><input name= "checkprof[]" value="Ana Maria Blanco Guerrero" id="prof02" type="checkbox" /> Blanco Guerrero, Ana María</td>
<td><input name= "checkprof[]" value="Rosario Rodriguez Gonzalez" id="prof03" type="checkbox" /> Rodríguez González, Rosario</td>
<td><input name= "checkprof[]" value="Jose Manuel Rodriguez Gonzalez" id="prof04" type="checkbox" /> Rodríguez González, José Manuel</td>
</tr>
<tr>
<td><input name= "checkprof[]" value="Maria del Carmen Blanco Cotta" id="prof05" type="checkbox" /> Blanco Cotta, María del Carmen</td>
<td><input name= "checkprof[]" value="Sofia Carmen Cotta Blanco" id="prof06" type="checkbox" /> Cotta Blanco, Sofía Carmen</td>
<td><input name= "checkprof[]" value="Mateo Jose Cotta Ventura" id="prof07" type="checkbox" /> Cotta Ventura, Mateo José</td>
<td><input name= "checkprof[]" value="Rosa Maria Rondan Ventura" id="prof08" type="checkbox" /> Rondán Ventura, Rosa María</td>
</tr>
<tr>
<td><input name= "checkprof[]" value="Maria Rondan Moya" id="prof09" type="checkbox" /> Rondán Moya, María</td>
<td><input name= "checkprof[]" value="Francisco Mateo Moya Garrido" id="prof10" type="checkbox" /> Moya Garrido, Francisco Mateo</td>
</tr>
</tbody>
</table>
<p> </p>
<script type="text/javascript">
$(document).ready(function(){
//CLAUSTRO
$("input[id=checkclaustro]").change(function(){
$('input[type=checkbox]').each( function() {
if($("input[id=checkclaustro]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
//PRIMARIA
$("input[id=checkprimaria]").change(function(){
$('input[id=prof02]').each( function()
{
if($("input[name=checkprimaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checkprimaria]").change(function(){
$('input[id=prof04]').each( function()
{
if($("input[id=checkprimaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checkprimaria]").change(function(){
$('input[id=prof06]').each( function()
{
if($("input[id=checkprimaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checkprimaria]").change(function(){
$('input[id=prof08]').each( function()
{
if($("input[id=checkprimaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checkprimaria]").change(function(){
$('input[id=prof10]').each( function()
{
if($("input[id=checkprimaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
//SECUNDARIA**************************************************************************
$("input[id=checksecundaria]").change(function(){
$('input[id=prof01]').each( function()
{
if($("input[id=checksecundaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checksecundaria]").change(function(){
$('input[id=prof03]').each( function()
{
if($("input[id=checksecundaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checksecundaria]").change(function(){
$('input[id=prof05]').each( function()
{
if($("input[id=checksecundaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checksecundaria]").change(function(){
$('input[id=prof07]').each( function()
{
if($("input[id=checksecundaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("input[id=checksecundaria]").change(function(){
$('input[id=prof09]').each( function()
{
if($("input[id=checksecundaria]:checked").length == 1){
this.checked = true;
} else {
this.checked = false;
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
//EQUIPOS EDUCATIVOS PRIMARIA 1A**************************************************************************
$("#equipos").change(function(){
$('input[id=prof01]').each( function()
{
if($("#equipos").val() == "prim_1a"){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("#equipos").change(function(){
$('input[id=prof03]').each( function()
{
if($("#equipos").val() == "prim_1a"){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("#equipos").change(function(){
$('input[id=prof04]').each( function()
{
if($("#equipos").val() == "prim_1a"){
this.checked = true;
} else {
this.checked = false;
}
});
});
//EQUIPOS EDUCATIVOS PRIMARIA 1B**************************************************************************
$("#equipos").change(function(){
$('input[id=prof02]').each( function()
{
if($("#equipos").val() == "prim_1b"){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("#equipos").change(function(){
$('input[id=prof04]').each( function()
{
if($("#equipos").val() == "prim_1b"){
this.checked = true;
} else {
this.checked = false;
}
});
});
$("#equipos").change(function(){
$('input[id=prof06]').each( function()
{
if($("#equipos").val() == "prim_1b"){
this.checked = true;
} else {
this.checked = false;
}
});
});
});
</script>
Valora esta pregunta


0