Salve ho un form :
codice:<label><input class="checkb" type="checkbox" name="italiano" value="1" onchange="check_lingue(this)" <?php if($risimage['italiano']==1) echo "checked"; ?>/> Italiano</label> <label><input class="checkb" type="checkbox" name="english" value="1" onchange="check_lingue(this)" <?php if($risimage['english']==1) echo "checked"; ?>/> English </label> <label><input class="checkb" type="checkbox" name="spanish" value="1" onchange="check_lingue(this)" <?php if($risimage['spanish']==1) echo "checked"; ?>/> Spanish</label> <p> </div> <div class="col-md-3 bordo-destra text-left"> <label> <input class="checkb" type="checkbox" name="french" value="1" onchange="check_lingue(this)" <?php if($risimage['french']==1) echo "checked"; ?>/> French</label> <label> <input class="checkb" type="checkbox" name="german" value="1" onchange="check_lingue(this)" <?php if($risimage['german']==1) echo "checked"; ?>/> German</label> <label> <input class="checkb" type="checkbox" name="russian" value="1" onchange="check_lingue(this)" <?php if($risimage['russian']==1) echo "checked"; ?>/> Russian</label> </div> <div class="col-md-3 bordo-destra text-left"> <label><input class="checkb" type="checkbox" name="japanese" value="1" onchange="check_lingue(this)"<?php if($risimage['japanese']==1) echo "checked"; ?>/> Japanese</label> <label> <input class="checkb" type="checkbox" name="portuguese" value="1" onchange="check_lingue(this)" <?php if($risimage['portuguese']==1) echo "checked"; ?>/> Portuguese</label> <label> <input class="checkb" type="checkbox" name="arabic" value="1" onchange="check_lingue(this)" <?php if($risimage['arabic']==1) echo "checked"; ?>/> Arabic</label> <label> <input class="checkb" type="checkbox" name="mandarin" value="1" onchange="check_lingue(this)" <?php if($risimage['mandarin']==1) echo "checked"; ?>/> Mandarin</label>
ho creato questa funzione che controlla all'iinizio quanti campi sono checked :
ho inoltre questa che modifica il numero totale :codice:function checklingueinizio(elemento){ if('document.form_edit_host.'+elemento+'.checked'){ quanti += 1; } if(quanti==0){ document.getElementById('lingue1').innerHTML = '<img src="img/no.png"> Seleziona almeno una lingua'; } else{ document.getElementById('lingue1').innerHTML = '<img src="img/si.png">'; } }
all'onload eseguo :codice:function check_lingue(elemento){ if(elemento.checked){ quanti += 1; } else{ quanti -= 1; } alert('quanti ='+quanti); if(quanti==0){ document.getElementById('lingue1').innerHTML = '<img src="img/no.png"> Seleziona almeno una lingua'; } else{ document.getElementById('lingue1').innerHTML = '<img src="img/si.png">'; } check_allok(); }
codice:checklingueinizio('italiano'); checklingueinizio('english'); checklingueinizio('spanish'); checklingueinizio('french'); checklingueinizio('german'); checklingueinizio('russian'); checklingueinizio('japanese'); checklingueinizio('portuguese'); checklingueinizio('arabic'); checklingueinizio('mandarin');
Il problema è che al caricamento sembra le veda tutte checked anche se solo alcune lo sono ....

 
			
			 
					
					
					
						 Rispondi quotando
  Rispondi quotando