1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
var info= {"id01":"info checkbox1",
"id02":"info checkbox2",
"id03":"info checkbox3",
"id04":"info checkbox4"
};
function manageList(chk) {
var sel =document.getElementById('sel');
//si c'est coché on ajoute l'option (on met comme value l'id de la checkbox
//c'est ajustable !
if (chk.checked) {
var option = new Option(info[chk.id],chk.id);
sel.options[sel.length] = option;
}
//et si c'es décoché, on cherche l'élément de la liste à supprimer
//recherche par son id précédemment instauré
else {
for (var i = 0; i<sel.length ; i++) {
if (sel.options[i].value==chk.id) {
sel.remove(i);
break;
}
}
}
}
</script>
</head>
<body>
<select id="sel">
</select>
<input type="checkbox" id="id01" onclick="manageList(this);"/>
<input type="checkbox" id="id02" onclick="manageList(this);"/>
<input type="checkbox" id="id03" onclick="manageList(this);"/>
<input type="checkbox" id="id04" onclick="manageList(this);"/>
</body>
</html> |
Partager