Salve, vorrei creare un form dove attraverso una form select possa decidere quante checkbox posso cliccare.
Ho abbozzato un codice ma non funzionano i javascript.
Potreste dirmi dove risiede l'errore/i?
Grazie.
vi allego le bozze dei codici
Codice HTML:
<form id="form5" action="/form/" enctype="multipart/form-data" method="post" name="form5" onsubmit="check_required('submit', '5'); return false;">
<div class="wdform_page_navigation" id="5pages"></div>
<input id="counter5" type="hidden" name="counter5" value="5" />
<input id="Itemid5" type="hidden" name="Itemid5" value="" />
<table class="wdform_table1" style="border-top: 0px solid black;" cellspacing="0" cellpadding="4">
<tbody class="wdform_tbody1" id="5form_view1">
<tr class="wdform_tr1">
<td class="wdform_td1">
<table class="wdform_table2">
<tbody class="wdform_tbody2">
<tr id="1">
<td class="wdform_select" id="1_label_section5" align="left" valign="middle"><span class="label" id="1_element_label5">Modulo</span><span class="required" id="1_required_element5"></span></td>
<td class="wdform_select toolbar_padding" id="1_element_section5" align="left" valign="middle"><input id="1_type5" type="hidden" name="1_type5" value="type_own_select" /><input id="1_required5" type="hidden" name="1_required5" value="no" />
<select id="1_element5" style="width: 65px;" onclick="controlloModulo()" name="1_element5" onchange="set_select(this)"><option id="1_option0" value="3-4-3">3-4-3</option><option id="1_option1" value="3-5-2">3-5-2</option><option id="1_option2" value="4-3-3">4-3-3</option><option id="1_option3" selected="selected" value="4-4-2">4-4-2</option><option id="1_option4" value="4-5-1">4-5-1</option><option id="1_option5" value="5-3-2">5-3-2</option><option id="1_option6" value="5-4-1">5-4-1</option></select></td>
</tr>
<tr id="4">
<td class="toolbar_padding" id="4_element_section5" colspan="2" align="left" valign="top">
<h2>Titolari</h2>
</td>
</tr>
<tr id="2">
<td id="2_label_section5" align="left" valign="top"><span class="label" id="2_element_label5">Portieri:</span><span class="required" id="2_required_element5"></span></td>
<td class=" toolbar_padding" id="2_element_section5" align="left" valign="top"><input id="2_type5" type="hidden" name="2_type5" value="type_checkbox" /><input id="2_required5" type="hidden" name="2_required5" value="no" /><input id="2_randomize5" type="hidden" name="2_randomize5" value="no" /><input id="2_allow_other5" type="hidden" name="2_allow_other5" value="0" /><input id="2_allow_other_num5" type="hidden" name="2_allow_other_num5" value="0" />
<table>
<tbody id="2_table_little">
<tr id="2_element_tr0">
<td id="2_td_little0" valign="top"><input id="2_element50" onclick="set_checked('2','0','5')" type="checkbox" name="2_element50" value="Buffon" /><label class="ch_rad_label" id="2_label_element0" for="2_element50">Buffon</label></td>
</tr>
<tr id="2_element_tr1">
<td id="2_td_little1" valign="top"><input id="2_element51" onclick="set_checked('2','1','5')" type="checkbox" name="2_element51" value="Gillet" /><label class="ch_rad_label" id="2_label_element1" for="2_element51">Gillet</label></td>
</tr>
<tr id="2_element_tr2">
<td id="2_td_little2" valign="top"><input id="2_element52" onclick="set_checked('2','2','5')" type="checkbox" name="2_element52" value="Sorrentino" /><label class="ch_rad_label" id="2_label_element2" for="2_element52">Sorrentino</label></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr id="3">
<td id="3_label_section5" align="left" valign="top"><span class="label" id="3_element_label5">Difensori:</span><span class="required" id="3_required_element5"></span></td>
<td class=" toolbar_padding" id="3_element_section5" align="left" valign="top"><input id="3_type5" type="hidden" name="3_type5" value="type_checkbox" /><input id="3_required5" type="hidden" name="3_required5" value="no" /><input id="3_randomize5" type="hidden" name="3_randomize5" value="no" /><input id="3_allow_other5" type="hidden" name="3_allow_other5" value="0" /><input id="3_allow_other_num5" type="hidden" name="3_allow_other_num5" value="0" />
<table>
<tbody id="3_table_little">
<tr id="3_element_tr0">
<td id="3_td_little0" valign="top"><input id="3_element50" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element50" value="Basta" /><label class="ch_rad_label" id="3_label_element0" for="3_element50">Basta</label></td>
</tr>
<tr id="3_element_tr1">
<td id="3_td_little1" valign="top"><input id="3_element51" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element51" value="Biava" /><label class="ch_rad_label" id="3_label_element1" for="3_element51">Biava</label></td>
</tr>
<tr id="3_element_tr2">
<td id="3_td_little2" valign="top"><input id="3_element52" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element52" value="Bonucci" /><label class="ch_rad_label" id="3_label_element2" for="3_element52">Bonucci</label></td>
</tr>
<tr id="3_element_tr3">
<td id="3_td_little3" valign="top"><input id="3_element53" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element53" value="Gastaldello" /><label class="ch_rad_label" id="3_label_element3" for="3_element53">Gastaldello</label></td>
</tr>
<tr id="3_element_tr4">
<td id="3_td_little4" valign="top"><input id="3_element54" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element54" value="Granqvist" /><label class="ch_rad_label" id="3_label_element4" for="3_element54">Granqvist</label></td>
</tr>
<tr id="3_element_tr5">
<td id="3_td_little5" valign="top"><input id="3_element55" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element55" value="Juan Jesus" /><label class="ch_rad_label" id="3_label_element5" for="3_element55">Juan Jesus</label></td>
</tr>
<tr id="3_element_tr6">
<td id="3_td_little6" valign="top"><input id="3_element56" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element56" value="Marquinhos" /><label class="ch_rad_label" id="3_label_element6" for="3_element56">Marquinhos</label></td>
</tr>
<tr id="3_element_tr7">
<td id="3_td_little7" valign="top"><input id="3_element57" onclick="controllaLimiteDif(num)" type="checkbox" name="3_element57" value="Samuel" /><label class="ch_rad_label" id="3_label_element7" for="3_element57">Samuel</label></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr class="wdform_footer">
<td colspan="100" valign="top"></td>
</tr>
</tbody>
</table>
Codice:
var selezionati = 0;
var max_selezionati = 2;
function controlloModulo()
switch (document.form5.1_element5.value) {
case "3-4-3": max_selezionati = 3; controllaLimiteDif(num);
break;
case "3-5-2": max_selezionati = 3; controllaLimiteDif(num);
break;
case "4-3-3": max_selezionati = 4; controllaLimiteDif(num);
break;
case "4-4-2": max_selezionati = 4; controllaLimiteDif(num);
break;
case "4-5-1": max_selezionati = 4; controllaLimiteDif(num);
break;
case "5-3-2": max_selezionati = 5; controllaLimiteDif(num);
break;
case "5-4-1": max_selezionati = 5; controllaLimiteDif(num);
break;
}
function controllaLimiteDif(num)
{
var oggetto = eval("document.form5.3_element5"+num);
if(oggetto.checked)
selezionati++;
else
selezionati--;
if(selezionati > max_selezionati)
{
oggetto.checked = false;
selezionati--;
}
}