IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Impresion textarea selon le choix javascript et php


Sujet :

JavaScript

Vue hybride

steph49 Impresion textarea selon le... 23/08/2023, 00h23
steph49 je met le code au cas ou ca... 23/08/2023, 16h49
Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2011
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2011
    Messages : 38
    Par défaut Impresion textarea selon le choix javascript et php
    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

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2011
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2011
    Messages : 38
    Par défaut
    je met le code au cas ou ca pourrait aider qqun qui fonctionne

    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
    <?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" style="padding-bottom: 1rem;">
    <tr>
    <td width="80" style="padding-top: .5rem;">
    <div align="left">
    Poste: <br><?= $tabe_poste[$i]; ?>
    </div>
    </td>
    <td><br>
    <textarea name="Txt_com<?= $i; ?>" cols="37" rows="4" id="Txt_com<?= $i; ?>" disabled="readonly" onclick="printTextArea('<?= $tabe_poste[$i]; ?>', '<?= $i ?>');" style="padding-bottom: 1rem;">
    <?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'];
     
    //= $data['Nom'] . ' ' . $data['Prenom'] . '  Présence essai: ' . $data['essait']."\n";
     echo $data['Nom'].' '.$data['Prenom'].'  Présence essai: '.$data['essait']."\n";
    }?>
    </textarea>
    </td>
    <td>
    Imprimer le poste:
    <input type="checkbox" name="chec_com<?= $i; ?>" value="1" id="chec_com<?= $i; ?>" onclick="printTextArea('<?= $tabe_poste[$i]; ?>', '<?= $i ?>');">
    </td>
    </tr>
    </table>
    <br>
    <?php endfor; ?>
     
     
    <script type="text/javascript">
    function printTextArea(nomPoste, eltId) {
    var text = document.getElementById(`Txt_com${eltId}`).value;
    var printWindow = window.open('', '', 'height=400,width=800');
    printWindow.document.write(`<html><head><title>Impression poste ${nomPoste} </title></head><body>`);
    printWindow.document.write(text.replace(/\n/gi, '<br>'));
    printWindow.document.write('</body></html>');
    printWindow.document.close();
    printWindow.print();
    }
    </script>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 01/08/2006, 23h24
  2. affichage selon le choix d'une liste déroulante
    Par cell dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 05/07/2006, 10h16
  3. [FORMULAIRE] affichage selon le choix dans une liste déroulante.
    Par gailup dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 25/06/2006, 14h58
  4. Réponses: 2
    Dernier message: 14/09/2005, 12h08
  5. Réponses: 2
    Dernier message: 23/06/2004, 13h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo