bonjour

j essaie d'adapter ce code javascript a mon formulaire php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
		<script type="text/javascript">
		        function printTextArea() {
			 var text = document.getElementById("Txt_com<?php echo $i; ?>").value;
			 var printWindow = window.open('', '', 'height=400,width=800');
			 printWindow.document.write('<html><head><title>Impression poste <?php echo $tabe_poste[$i]; ?> </title></head><body>');
			 printWindow.document.write(text.replace(/\n/gi,'<br>'));
			 printWindow.document.write('</body></html>');
			 printWindow.document.close();
			 printWindow.print();
				}
                  </script>
lorsque je coche une checkbox ca me lance le script tout est ok.
le problème c est que cela m imprime automatiquement la dernière textarea même si je sélectionne la seconde par exemple.
je met le code complet c’a serra plus parlant
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
<?php
        //creation de la boucle for et affichage du tableau avec les textarea   
        for($i = 0; $i < count($tabe_poste); $i++) {
        ?>
	<table class="bouton1" align="center"  width="560px">
	<tr>
	<td width=80><br><div align="left">Poste: <br><?php echo $tabe_poste[$i]; ?></td>
	<td><textarea name="Txt_com<?php echo $i; ?>" cols="37" rows="4" id="Txt_com<?php echo $i; ?>"  disabled="readonly"  onclick="printTextArea();">
	<?php
                        //recuperation des personne poste par 
                         $Rqs = mysqli_query($link, "SELECT * FROM inscription WHERE Num_poste='$tabe_poste[$i]' ");
                        while($data = mysqli_fetch_array($Rqs)) {
                                                                                 
                        $Nom       = $data['Nom']; 
                        $Prenon     = $data['Prenom'];
                        $Essait     = $data['essait'];
                                                                
                echo $data['Nom'].' '.$data['Prenom'].'  Présence essai: '.$data['essait']."\n";
        }                                                       
        ?>
	</textarea></font><br><br>
	</td>
	<td>Inprimer:<?php echo $i; ?><input type="checkbox" name="chec_com<?php echo $i; ?>" value="1" id="chec_com<?php echo $i; ?>" onclick="printTextArea();">
<script type="text/javascript">
  function printTextArea() {
  var text = document.getElementById("Txt_com<?php echo $i; ?>").value;
  var printWindow = window.open('', '', 'height=400,width=800');
  printWindow.document.write('<html><head><title>Impression poste <?php echo $tabe_poste[$i]; ?> </title></head><body>');
  printWindow.document.write(text.replace(/\n/gi,'<br>'));
  printWindow.document.write('</body></html>');
  printWindow.document.close();
  printWindow.print();
	}
</script></td>
 
</tr>
</table>	
<br>								
<?Php
}
?>
une idée