Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [JS] Controllo sui Checkbox e Select

    Salve a tutti,

    Ho un problema, vorrei che al check ed al uncheck di un mio input checkbox si checkano e uncheckano gli altri

    codice:
    <script language="javascript">
     function copiastato() {
       if (document.getElementById('manufacturer').checked==true) {   
           document.getElementById('manufacturer1').checked=true;
           document.getElementById('manufacturer2').checked=true;
           document.getElementById('manufacturer3').checked=true;
           document.getElementById('manufacturer4').checked=true;
       } else {
           document.getElementById('manufacturer1').checked=false;
           document.getElementById('manufacturer2').checked=false;
           document.getElementById('manufacturer3').checked=false;
           document.getElementById('manufacturer4').checked=false;
       };
       if (document.getElementById('Vendor').checked==true) {   
           document.getElementById('Vendor1').checked=true;
           document.getElementById('Vendor2').checked=true;
           document.getElementById('Vendor3').checked=true;
           document.getElementById('Vendor4').checked=true;
       } else {
           document.getElementById('Vendor1').checked=false;
           document.getElementById('Vendor2').checked=false;
           document.getElementById('Vendor3').checked=false;
           document.getElementById('Vendor4').checked=false;
       };
    }
    </script>
    codice:
    <input type="checkbox" name="manufacturer" id="manufacturer" value="1" onClick="copiastato();">manufacturer
    <input type="checkbox" name="manufacturer1" id="manufacturer1" value="1" disabled>manufacturer1
    <input type="checkbox" name="manufacturer2" id="manufacturer2" value="1" disabled>manufacturer2
    <input type="checkbox" name="manufacturer3" id="manufacturer3" value="1" disabled>manufacturer3
    <input type="checkbox" name="manufacturer4" id="manufacturer4" value="1" disabled>manufacturer4
    
    <input type="checkbox" name="Vendor" id="Vendor" value="1" onClick="copiastato();">Vendor
    <input type="checkbox" name="Vendor1" id="Vendor1" value="1" disabled>Vendor1
    <input type="checkbox" name="Vendor2" id="Vendor2" value="1" disabled>Vendor2
    <input type="checkbox" name="Vendor3" id="Vendor3" value="1" disabled>Vendor3
    <input type="checkbox" name="Vendor4" id="Vendor4" value="1" disabled>Vendor4
    Questo codice non mi funziona, la stessa cosa la vorrei per le select ma non so dove partire, mi da un input a riguardo. Ringrazio in anticipo.
    No Blitz No Party!

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    mah, mi risulta funzionare

    che poi, il tutto si puo' condensare in
    codice:
     function copiastato(ck) {
       var ckId=ck.id;
       for(var k=1;k<=4;k++){
          document.getElementById(ckId+k).checked=ck.checked;
       }
     }
    <input type="checkbox" name="manufacturer" id="manufacturer" value="1" onClick="copiastato(this);">


    la select cosa dovrebbe fare precisamente? solo 2 option, checked e unchecked?

  3. #3
    Nemmeno funziona, però ho notato che se metto entrambi codici in una pagina html vuota e per vuota intendo nessun riferimento a framework o librerie jquary mi funziona.

    Questi check si trovano all'interno di tab non è che è per questo che non funzionano?

    E per quanto riguarda le select, io nella select 'comandante' option revisione 1, revisione 2 e revisione 3, quindi tre selezioni.

    Le altre select devono prendere lo stato checked della select comandate. Tipo comandate revisione 1, le altre select devono avere revisione 1.
    No Blitz No Party!

  4. #4
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Ma... io l'ho letto tre volte e non c'ho capito nulla, forse può aiutare un link alla pagina pubblica.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.