Visualizzazione dei risultati da 1 a 7 su 7

Discussione: selezione totale

  1. #1

    selezione totale

    Buongiorno, spero possiate aiutarmi con questo problema, ho un elenco di record e per ogniuno ho un checkbox, quando seleziono il checkbox cambia colore la riga della tabella, questo è il codice:

    <tr bgcolor=#f9f4e1 id="cc_0">
    <td>
    <input type="checkbox" name="msg_0" value=1 onclick=if(msg_0.checked){cc_0.bgColor='#F1EAD1'}e lse{cc_0.bgColor='#f9f4e1'}>
    </td>
    </tr>

    poi ho invece un checkbox che mi spunta tutti i checkbox, questo è il codice:

    function sel() {
    with(document.form1) {
    for(i=0;i<elements.length;i++) {
    thiselm = elements[i];
    if(thiselm.name.substring(0,3) == 'msg')
    thiselm.checked = !thiselm.checked
    }
    }
    }
    Il problema è che quando spunto questo, non cambia il colore delle righe della tabella.

    Come posso risolvere questo problema?

    Grazie mille

  2. #2
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    Ciao adweb,

    la funzione sel() non spunta tutti i checkbox... ma fa il contrario di ogni uno (se è checkato lo schecka e viceversa)
    comunque per cambiare il colore delle colonne
    codice:
    function sel(){ 
    	with(document.form1){ 
    		for(i=0;i<elements.length;i++){ 
    			thiselm = elements[i]; 
    			if(thiselm.name.substring(0,3) == 'msg'){
    				thiselm.checked = !thiselm.checked 
    				colonna=document.getElementById('cc_'+thiselm.name.substr(4))
    				if(thiselm.checked)colonna.bgColor='#F1EAD1'
    				else colonna.bgColor='#f9f4e1'
    			}
    		} 
    	} 
    }

  3. #3
    nel caso volessi far si che mi chekki tutti e mi dechekki tutti come deve essere modificato?

    grazie mille

  4. #4
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    potresti fare così
    codice:
    function sel(truefalse){ 
    	with(document.form1){ 
    		for(i=0;i<elements.length;i++){ 
    			thiselm = elements[i]; 
    			if(thiselm.name.substring(0,3) == 'msg'){
    				thiselm.checked = truefalse 
    				colonna=document.getElementById('cc_'+thiselm.name.substr(4))
    				if(thiselm.checked)colonna.bgColor='#F1EAD1'
    				else colonna.bgColor='#f9f4e1'
    			}
    		} 
    	} 
    }
    da richiamare con true per checkare e false per decheckare

  5. #5
    scusa l'ignoranza ma mi faresti un esempio pratico?

    scusami ancora

  6. #6
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    ecco qua :gren:
    codice:
    <form name="form1">
    <table>
    <tr bgcolor=#f9f4e1 id="cc_0"> 
    <td> 
    <input type="checkbox" name="msg_0" value=1 onclick=if(msg_0.checked){cc_0.bgColor='#F1EAD1'}else{cc_0.bgColor='#f9f4e1'}> 
    </td> 
    <tr bgcolor=#f9f4e1 id="cc_1"> 
    <td> 
    <input type="checkbox" name="msg_1" value=1 onclick=if(msg_1.checked){cc_1.bgColor='#F1EAD1'}else{cc_1.bgColor='#f9f4e1'}> 
    </td> 
    </tr> 
    <tr bgcolor=#f9f4e1 id="cc_2"> 
    <td> 
    <input type="checkbox" name="msg_2" value=1 onclick=if(msg_2.checked){cc_2.bgColor='#F1EAD1'}else{cc_2.bgColor='#f9f4e1'}> 
    </td> 
    
    </table>
    poi ho invece un checkbox che mi spunta tutti i checkbox, questo è il codice: 
    <script>
    function sel(truefalse){ 
    	with(document.form1){ 
    		for(i=0;i<elements.length;i++){ 
    			thiselm = elements[i]; 
    			if(thiselm.name.substring(0,3) == 'msg'){
    				thiselm.checked = truefalse 
    				colonna=document.getElementById('cc_'+thiselm.name.substr(4))
    				if(thiselm.checked)colonna.bgColor='#F1EAD1'
    				else colonna.bgColor='#f9f4e1'
    			}
    		} 
    	} 
    } 
    </script>
    <input type="checkbox" value="tutti" onclick="sel(this.checked)">
    </form>

  7. #7
    sei un grande, grazie mille...

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.