Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: Select deselect all

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072

    Select deselect all

    Ciao a tutti, nelle mie pagine uso uno script che mi consente di selezionare automaticamente tutti i checkbox di una colonna.

    Il problema è che quando nella griglia ho due colonne con due tipologie di checkbox, io vorrei solo selezionare (tutti) i checkbox di una colonna.... ora invece vengono selezionate tutte.

    Mi potete aiutare?

    Grazie



    codice:
    <script language=JavaScript> 
    <!--
    function confirmDelete (frm) {
    
     // loop through all elements
     for (i=0; i<frm.length; i++) {
    
     // Look for our checkboxes only
     if (frm.elements[i].name.indexOf ('DeleteThis') !=-1) {
     // If any are checked then confirm alert, otherwise nothing happens
     if(frm.elements[i].checked) {
     return confirm ('Confermi la cancellazione?')
     }
     }
     }
    }
    
    
    
    function select_deselectAll (chkVal, idVal) {
    var frm = document.forms[0];
    // loop through all elements
     for (i=0; i<frm.length; i++) {
     // // Look for our Header Template's Checkbox
     if (idVal.indexOf ('CheckAll') != -1) {
     // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
     if(chkVal == true) {
     frm.elements[i].checked = true;
     } else {
     frm.elements[i].checked = false;
     }
     // Work here with the Item Template's multiple checkboxes
     } else if (idVal.indexOf('DeleteThis') != -1) {
     // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
     if(frm.elements[i].checked == false) {
     frm.elements[1].checked = false; // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
     }
     }
     }
    }//--> 
    </script>

    La mia è una griglia generata da .NET, vi posto comunque un esempio dell'HTML generato (se puo' servire)

    Codice PHP:


    <table cellspacing="0" rules="all" border="1" id="ctl00_Main_gwSpedizioni" style="width:90%;border-collapse:collapse;">
            <
    tr style="background-color:Silver;height:20px;">
                <
    th scope="col">
                                <
    div align="center"
                                <
    input id="ctl00_Main_gwSpedizioni_ctl01_CheckAll" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl01$CheckAllonclick="javascript: return select_deselectAll (this.checked, this.id);" />
                                </
    div
                            </
    th>

    ......
            </
    tr><tr style="height:20px;">
                <
    td style="width:35px;">
                                <
    div align="center"
                                 <
    input id="ctl00_Main_gwSpedizioni_ctl02_DeleteThis" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl02$DeleteThis/>
                                 
                                </
    div
                            </
    td>

    ......


                                        <
    span disabled="disabled"><input id="ctl00_Main_gwSpedizioni_ctl02_chkNostroConto" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl02$chkNostroContodisabled="disabled" /></span>
                                   </
    td>
            </
    tr><tr style="background-color:#E0E0E0;height:20px;">
                <
    td style="width:35px;">
                                <
    div align="center"
                                 <
    input id="ctl00_Main_gwSpedizioni_ctl03_DeleteThis" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl03$DeleteThis/>
                                 
                                </
    div
                            </
    td><td style="width:80px;">


    .......

                                        <
    span disabled="disabled"><input id="ctl00_Main_gwSpedizioni_ctl03_chkNostroConto" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl03$chkNostroContodisabled="disabled" /></span>
                                   </
    td>
            </
    tr

  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Please help me!!

  3. #3
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Aggiungi una classe hai checkbox che vuoi distingure tipo:
    <input id="ctl00_Main_gwSpedizioni_ctl02_DeleteThis" class="col1" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl02$DeleteThis" />
    <input id="ctl00_Main_gwSpedizioni_ctl01_CheckAll" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl01$CheckAll" onclick="java-script: return select_deselectAll (this.checked, this.id, 'col1');" />
    function select_deselectAll (chkVal, idVal,classe){....
    if(chkVal == true && classe='col1') {
    frm.elements[i].checked = true;
    } else {
    frm.elements[i].checked = false;
    }
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Grazie per l'aiuto, quindi aggiungo una classe al mio checkbox che voglio gestire (intendo a tutti quelli della colonna interessata)

    esempio class="col1"

    la chiamata (dalla griglia) sarà:

    select_deselectAll (this.checked, this.id, 'col1');


    a questo punto il JS diventerà


    function select_deselectAll (chkVal, idVal,classe){....
    if(chkVal == true && classe='col1') {
    frm.elements[i].checked = true;
    } else {
    frm.elements[i].checked = false;
    }

    ma tutti il vecchio JS che funzionava correttamente??

    come verrà modificato


    codice:
    function select_deselectAll (chkVal, idVal) {
    var frm = document.forms[0];
    // loop through all elements
     for (i=0; i<frm.length; i++) {
     // // Look for our Header Template's Checkbox
     if (idVal.indexOf ('CheckAll') != -1) {
     // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
     if(chkVal == true) {
     frm.elements[i].checked = true;
     } else {
     frm.elements[i].checked = false;
     }
     // Work here with the Item Template's multiple checkboxes
     } else if (idVal.indexOf('DeleteThis') != -1) {
     // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
     if(frm.elements[i].checked == false) {
     frm.elements[1].checked = false; // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
     }
     }
     }
    }
    Grazie per l'aiuto

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Ho scritto qualche fesseria??


  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Nessuna dritta??

  7. #7
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    Immagino sarà cosi:

    codice:
    function select_deselectAll (chkVal, idVal, classe) {
    var frm = document.forms[0];
    // loop through all elements
     for (i=0; i<frm.length; i++) {
     // // Look for our Header Template's Checkbox
     if (idVal.indexOf ('CheckAll') != -1) {
     // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
     if(chkVal == true && classe=='col1') {
    frm.elements[i].checked = true;
    } else {
    frm.elements[i].checked = false;
    }
     // Work here with the Item Template's multiple checkboxes
     } else if (idVal.indexOf('DeleteThis') != -1) {
     // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
     if(frm.elements[i].checked == false) {
     frm.elements[1].checked = false; // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
     }
     }
     }
    }
    Non l'ho provato quindi fai un po' di test...

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Sbaglio qualche cosa... come dicevo uso .NET quindi nella definizione della colonna della griglia ho messo


    Codice PHP:

    <asp:TemplateField>
                            <
    ItemStyle Width="35px"></ItemStyle>
                            <
    HeaderTemplate>
                                <
    div align="center"
                                <
    asp:CheckBox ID="CheckAll" OnClick="javascript: return select_deselectAll (this.checked, this.id, 'col1');" runat="server" />
                                </
    div
                            </
    HeaderTemplate>
                            <
    ItemTemplate>
                                <
    div align="center"
                                 <
    asp:CheckBox ID="DeleteThis" runat="server" Class="col1" />
                                 <
    asp:Label ID="StoreID" Text='<%# DataBinder.Eval (Container.DataItem, "id") %>' runat="server" Visible="false"/>
                                </
    div
                            </
    ItemTemplate>
                        </
    asp:TemplateField

    poi nel JS

    Codice PHP:

    "function select_deselectAll (chkVal, idVal, classe) {\n" +
            
    "var frm = document.forms[0];\n" +
            
    "// loop through all elements\n" +
            
    " for (i=0; i<frm.length; i++) {\n" +
            
    " // // Look for our Header Template's Checkbox\n" +
            
    " if (idVal.indexOf ('CheckAll') != -1) {\n" +
            
    " // Check if main checkbox is checked, then select or deselect datagrid checkboxes \n" +
            
    " if(chkVal == true && classe=='col1') {\n" +
            
    " frm.elements[i].checked = true;\n" +
            
    " } else {\n" +
            
    " frm.elements[i].checked = false;\n" +
            
    " }\n" +
            
    " // Work here with the Item Template's multiple checkboxes\n" +
            
    " } else if (idVal.indexOf('DeleteThis') != -1) {\n" +
            
    " // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox\n" +
            
    " if(frm.elements[i].checked == false) {\n" +
            
    " frm.elements[1].checked = false; // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox\n" +
            
    " }\n" +
            
    " }\n" +
            
    " }\n" +
            
    "}" +
            
    "//--> \n" +
            
    "</script>"


    Non funziona... o meglio seleziona (come prima) anche colonne che non c'entrano niente .... tra l'altro è strano che lo faccia anche ora vista la condizione

    cmq nell'HTML, quello che io avevo inserito in .NET :

    Class="col1"

    diventa:

    <span class="col1"><input id="ctl00_Main_gwSpedizioni_ctl02_DeleteThis" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl02$DeleteThis" /></span>

    quindi il tag class non è inserito nel campo input

    Grazie

  9. #9
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    Effettivamente qualcosa non quadra... penso sia meglio aspettare una risposta di andrea perche a me sfugge qualcosa... che senso ha inserire il controllo classe == 'col1' se al metodo viene sempre passata la stringa col1? cioè quella condizione sarà sempre a true no? boh forse mi sto perdendo qualcosa.


  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Infatti!! Pur non creandomi correttamente la class dentro l'input vengono cmq chekkati.... proprio perchè forse, come dici, è sempre a true!

    Thanks

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 © 2025 vBulletin Solutions, Inc. All rights reserved.