Si vous utilisez Prototype JS, vous trouverez peut-être ce blog utile. Il donne un moyen assez concis pour effectuer un tout sélectionner.
http://www.ryboe.com/2008/07/10/select-all-checkboxes-with-prototype-js.html
À votre avis, vous pouvez utiliser l'extrait suivant pour créer un lien « Sélectionner tout »:
<%= link_to_function("Select All","checkboxes.each(function(e){ e.checked = 1 })") %>
En outre, vous aurez besoin du code Javascript suivant quelque part sur la même page (ou peut-être même abstraire vers le fichier public/javascripts/application.js
var checkboxes = [];
checkboxes = $$('input').each(function(e){ if(e.type == 'checkbox') checkboxes.push(e) });
var form = $('options'); /* Replace 'options' with the ID of the FORM element */
checkboxes = form.getInputs('checkbox');
Voici la source complète d'un exemple de travail, si cela ne fonctionne pas yo Vous devrez peut-être vérifier que vos bibliothèques JS se chargent correctement.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://www.google.com/jsapi" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var checkboxes;
google.load("prototype", "1.6");
google.setOnLoadCallback(function(){
checkboxes = [];
checkboxes = $$('input').each(function(e){ if(e.type == 'checkbox') checkboxes.push(e) });
var form = $('options'); /* Replace 'options' with the ID of the FORM element */
checkboxes = form.getInputs('checkbox');
});
</script>
</head>
<body>
<form id="options">
<fieldset><input type="text" value="test"></fieldset>
<fieldset><input type="checkbox" value=0> 0</fieldset>
<fieldset><input type="checkbox" value=1> 1</fieldset>
<fieldset><input type="checkbox" value=2> 2</fieldset>
<fieldset><input type="checkbox" value=3> 3</fieldset>
</form>
<a href="#" onclick="checkboxes.each(function(e){e.checked = 1})">Select All</a>
</body>
</html>
voir http: // stackoverflow.com/questions/386281/how-to-implement-select-all-check-box-in -html –