bonjour,
dans le cadre de mon apprentissage en javascript, je cherche a r�cup�rer la valeur lors du clic sur un checkbox.
pour la validation du formulaire cela fonctionne. Mais pour la s�lection individuel je ne comprend pas ce qu'il ne colle pas.
merci
Code : S�lectionner tout - Visualiser dans une fen�tre � part
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Untitled Document</title> <script type="text/javascript"> //<!CDATA[ window.onload=setupEvents; function setupEvents(evnt){ document.someForm.onsubmit=checkForm; document.someForm.ckbox.onclick=dcheckBox; } function dcheckBox(evnt){ var buttons = document.someForm.ckbox; for(var i=0;i<buttons.length; i++){ if(buttons[i].checked){ alert(buttons[i].value); //txtSelect.value = buttons[i].value; } } //Pas de traitement côté serveur : annuler l'envoi return false; } function checkForm(evnt){ var buttons = document.someForm.ckbox; for(var i=0;i<buttons.length; i++){ if(buttons[i].checked){ alert(buttons[i].value); } } //Pas de traitement côté serveur : annuler l'envoi return false; } //]]> </script> </head> <body> <p>Sélection cases a cocher</p> <form name="someForm" action=""> <input type="checkbox" name="ckbox" value="checkBox1" /> checkbox 1 <br/> <input type="checkbox" name="ckbox" value="checkBox2" /> checkbox 2 <br/> <input type="checkbox" name="ckbox" value="checkBox3" /> checkbox 3 <br/> <input type="checkbox" name="ckbox" value="checkBox4" /> checkbox 4 <br/> <input type="submit" value="Envoyer" /> </form> </body> </html>
Partager