Affiche automatique après une sélection dans un formulaire
dgdaphp
-
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
Salut la communauté j'ai un pti souci de code. J'ai crée un formulaire dans lequel j'ai inserer une liste de menu qui affiche les noms des agents dans la BD, un champ de text pour afficher les prenom et un autre pour le genre, en fait je veux une chose: lorsque je sélectionne un nom, je veux que le prénom et le genre du nom sélectionné s'affiche automatiquement.
Voici mon code:
EDIT : AJOUT DES BALISES DE CODE...
Merci de bien vouloir utiliser la coloration syntaxique (les balises de code) lorsque tu postes du code sur le forum.
Explications disponibles ici :
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
Voici mon code:
<?php require_once('../Connections/gesco1.php'); ?> <?php mysql_select_db($database_gesco1, $gesco1); $query_Rsnomlistagent = "SELECT agent.NOM FROM agent"; $Rsnomlistagent = mysql_query($query_Rsnomlistagent, $gesco1) or die(mysql_error()); $row_Rsnomlistagent = mysql_fetch_assoc($Rsnomlistagent); $totalRows_Rsnomlistagent = mysql_num_rows($Rsnomlistagent); mysql_select_db($database_gesco1, $gesco1); $query_Rslistprenom = "select distinct PRENOM from SELECT_AFFECTATION where nom='NOM'"; $Rslistprenom = mysql_query($query_Rslistprenom, $gesco1) or die(mysql_error()); $row_Rslistprenom = mysql_fetch_assoc($Rslistprenom); $totalRows_Rslistprenom = mysql_num_rows($Rslistprenom); mysql_select_db($database_gesco1, $gesco1); $query_Rspren = "select distinct PRENOM from SELECT_AFFECTATION where nom='ADOUA'"; $Rspren = mysql_query($query_Rspren, $gesco1) or die(mysql_error()); $row_Rspren = mysql_fetch_assoc($Rspren); $totalRows_Rspren = mysql_num_rows($Rspren); ?><!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"> <!-- DW6 --> <head> <!-- Copyright 2005 Macromedia, Inc. All rights reserved. --> <title>Page d'accueil</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="../css/mm_spa.css" type="text/css" /> <style type="text/css"> <!-- .Style2 {color: #FFFFFF} .Style5 { color: #1700AB; font-weight: bold; font-size: 9px; font-style: italic; } .Style9 {font-size: 9px} .Style10 { color: #FF0000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; } .Style12 {color: #0000FF; font-size: 10px; font-weight: bold; } .Style17 { font-size: 25px; font-weight: bold; font-family: Algerian; color: #9900FF; } .Style18 { font-family: Algerian; color: #9900FF; } .Style13 {color: #0000FF} --> #menu-gesco, #menu-gesco ul{ padding:0; margin:0; list-style:none; text-align:center; } #menu-gesco li{ display:inline-block; position:relative; border-radius:6px 6px 0 0; } #menu-gesco ul li{ display:inherit; border-radius:0; } #menu-gesco ul li:hover{ border-radius:0; } #menu-gesco ul li:last-child{ border-radius:0 0 8px 8px; } #menu-gesco ul{ position:absolute; max-height:0; left: 0; right: 0; overflow:hidden; -moz-transition: .8s all .3s; -webkit-transition: .8s all .3s; transition: .8s all .3s; } #menu-gesco li:hover ul{ max-height:15em; } /* background des liens menus */ #menu-gesco li:first-child{ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(2){ background-color: #3399FF; background-image: -webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(3){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(4){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(5){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(6){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(7){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(8){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(9){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:nth-child(10){ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } #menu-gesco li:last-child{ background-color: #3399FF; background-image:-webkit-linear-gradient(top, #3399FF 0%, #3399FF 100%); background-image:linear-gradient(to bottom, #3399FF 0%, #3399FF 100%); } /* background des liens sous menus */ #menu-gesco li:first-child li{ background:#3399FF; } #menu-gesco li:nth-child(2) li{ background:#3399FF; } #menu-gesco li:nth-child(3) li{ background:#3399FF; } #menu-gesco li:nth-child(4) li{ background:#3399FF; } #menu-gesco li:nth-child(5) li{ background:#3399FF; } #menu-gesco li:nth-child(6) li{ background:#3399FF; } #menu-gesco li:nth-child(7) li{ background:#3399FF; } #menu-gesco li:nth-child(8) li{ background:#3399FF; } #menu-gesco li:nth-child(9) li{ background:#3399FF; } #menu-gesco li:nth-child(10) li{ background:#3399FF; } #menu-gesco li:last-child li{ background:#3399FF; } /* background des liens menus et sous menus au survol */ #menu-gesco li:first-child:hover, #menu-gesco li:first-child li:hover{ background:#3399FF; } #menu-gesco li:nth-child(2):hover, #menu-gesco li:nth-child(2) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(3):hover, #menu-gesco li:nth-child(3) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(4):hover, #menu-gesco li:nth-child(4) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(5):hover, #menu-gesco li:nth-child(5) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(6):hover, #menu-gesco li:nth-child(6) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(7):hover, #menu-gesco li:nth-child(7) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(8):hover, #menu-gesco li:nth-child(8) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(9):hover, #menu-gesco li:nth-child(9) li:hover{ background:#3399FF; } #menu-gesco li:nth-child(10):hover, #menu-gesco li:nth-child(10) li:hover{ background:#3399FF; } #menu-gesco li:last-child:hover, #menu-gesco li:last-child li:hover{ background:#3399FF; } /* les a href */ #menu-gesco a{ text-decoration:none; display:block; padding:10px 50px; color:#fff; font-family:arial; } #menu-gesco ul a{ padding:20px 0; } #menu-gesco li:hover li a{ color:#fff; text-transform:inherit; } #menu-gesco li:hover a, #menu-gesco li li:hover a{ color:#000; } .Style19 {color: #000000} body,td,th { color: #000000; } body { background-color: #FFFFFF; } .Style20 { font-size: 25px; color: #000000; } </style> </head> <body background="../images/mm_bg_red.gif"> <table height="958" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr bgcolor="#220103"> <td colspan="2" rowspan="2" nowrap="nowrap" bgcolor="#55FFFF"><img src="../images/logo police.png" alt="Header image" width="215" height="191" border="0" /></td> <td height="55" colspan="2" valign="bottom" nowrap="nowrap" bgcolor="#55FFFF" id="logo"><div align="center"> <p align="center"><span class="Style17">GESCO V1.0</span></p> <p align="center" class="Style18">Gestion de la Main courante et du Fichier des Délinquants</p> <h1> </h1> </div></td> <td width="201" rowspan="2" bgcolor="#55FFFF"> </td> <td width="13" rowspan="2"> </td> </tr> <tr bgcolor="#220103"> <td height="48" colspan="2" valign="top" nowrap="nowrap" bgcolor="#55FFFF" id="tagline"><div align="center" class="Style2"> <p> </p> <p class="Style12">Force - Efficacité - Discipline </p> </div></td> </tr> <tr bgcolor="#FF9900"> <td height="2" colspan="6" bgcolor="#00CCFF"><img src="../images/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td> </tr> <tr bgcolor="#FF080E"> <td colspan="6"><img src="../images/mm_spacer.gif" alt="" width="1" height="2" border="0" /></td> </tr> <tr bgcolor="#FF9900"> <td colspan="6"><img src="../images/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td> </tr> <tr bgcolor="#FF080E"> <td colspan="6" bgcolor="#55FFFF"><img src="../images/mm_spacer.gif" alt="" width="1" height="18" border="0" /> <ul id="menu-gesco"> <li> <a href="Accueil_admin.php">Accueil</a> </li> <li><a href="journal.php">Journal</a> </li> <li><a href="users.php">Utilisateurs</a> </li> <li> <a href="Accueil_admin.php">Création</a> <ul><li><a href="ccp.php">CCP</a></li> <li><a href="cpa.php">CPA</a></li> </ul> </li> <li><a href="Accueil_admin.php"> Commissariarriats</a> <ul><li><a href="CCPconfiguration.php">Commissariats Centraux de Police</a></li> </ul> </li> <li><a href="Accueil_admin.php">Gestion Base des données</a> </li> <li><a href="../deconnexion.php">Déconnexion</a></li> </ul> </td> </tr> <tr bgcolor="#FF9900"> <td colspan="6"><img src="../images/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td> </tr> <tr bgcolor="#FF080E"> <td colspan="6"><img src="../images/mm_spacer.gif" alt="" width="1" height="2" border="0" /></td> </tr> <tr bgcolor="#FF9900"> <td colspan="6" bgcolor="#00CCFF"><img src="../images/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td> </tr> <tr> <td width="165" valign="top" id="navborder"><table width="212" height="87" border="0"> <tr> <td width="213" height="83"> </td> </tr> </table> <br /></td> <td width="50"><img src="../images/mm_spacer.gif" alt="" width="50" height="1" border="0" /></td> <td width="837" valign="top"><img src="../images/mm_spacer.gif" alt="" width="305" height="1" border="0" /><br /> <br /> <br /> <form id="form1" name="affiche_dernier_enreg" method="post" action=""> <?php include("gesco.php"); $result=mysql_query("select distinct PRENOM from SELECT_AFFECTATION where nom='' "); if($enreg=mysql_fetch_array($result)); { $ncomi=$enreg[0]; } ?> <p align="center">Nom de l'Agent <select name="select"> <?php do { ?> <option value="<?php echo $row_Rsnomlistagent['NOM']?>"<?php if (!(strcmp($row_Rsnomlistagent['NOM'], $row_Rsnomlistagent['NOM']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Rsnomlistagent['NOM']?></option> <?php } while ($row_Rsnomlistagent = mysql_fetch_assoc($Rsnomlistagent)); $rows = mysql_num_rows($Rsnomlistagent); if($rows > 0) { mysql_data_seek($Rsnomlistagent, 0); $row_Rsnomlistagent = mysql_fetch_assoc($Rsnomlistagent); } ?> </select> Prénom de l'Agent <input type="text" name="textpren" value="<?php echo $ncomi ; ?>"/> Genre <select name="select3"> <option value="M">Masculin</option> <option value="F">Féminin</option> </select> </p> <p align="center"> <input type='button' name='rechercher' value='afficher' onClick='dispNomPrenom()'> </p> <p> </p> </form> <p align="center"> </p> <p> <br /> <br /> </p></td> <td width="50"><img src="mm_spacer.gif" alt="" width="50" height="1" border="0" /></td> <td width="4" valign="top"><br /></td><td width="4"> </td> </tr> <tr> <td width="18"> </td> <td width="197"> </td> <td width="1601"><table width="1601" height="18" border="0"> <tr> <td width="1595" height="14"><div align="center" class="Style9"> <div align="left"><span class="Style10">-----------------------------------------------------Copyright (c) 2015-2025 by ARPCE - Système d'Information (SI)DGDA&MA -------------------------------------</span><span class="Style10">----------------</span></div> </div></td> </tr> </table></td> <td width="50"> </td> <td width="4"> </td> <td width="4"> </td> </tr> </table> </body> </html> <?php mysql_free_result($Rsnomlistagent); mysql_free_result($Rslistprenom); mysql_free_result($Rspren); ?>
EDIT : AJOUT DES BALISES DE CODE...
Merci de bien vouloir utiliser la coloration syntaxique (les balises de code) lorsque tu postes du code sur le forum.
Explications disponibles ici :
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
A voir également:
- Affiche automatique après une sélection dans un formulaire
- Whatsapp formulaire opposition - Guide
- Réponse automatique thunderbird - Guide
- Recherche automatique des chaînes ne fonctionne pas - Guide
- Logiciel de sauvegarde automatique gratuit - Guide
- Formulaire de réclamation facebook - Guide
1 réponse
Bonjour,
Tu veux donc que cette action se produise lorsque tu selectionnes un "nom" dans ton SELECT ?
Pour cela, sans avoir à repasser par un SUBMIT de ta page.. tu peux utiliser l'évènement : ONCHANGE et faire appel... non pas à du PHP... mais à du JAVASCRIPT. ( des liste liées ..ou de l'AJAX).
Par exemple :
https://forum.phpfrance.com/tutoriels/formulaires-listes-deroulantes-dynamiques-liees-t4562.html
lorsque je sélectionne un nom, je veux que le prénom et le genre du nom sélectionné s'affiche automatiquement.
Tu veux donc que cette action se produise lorsque tu selectionnes un "nom" dans ton SELECT ?
Pour cela, sans avoir à repasser par un SUBMIT de ta page.. tu peux utiliser l'évènement : ONCHANGE et faire appel... non pas à du PHP... mais à du JAVASCRIPT. ( des liste liées ..ou de l'AJAX).
Par exemple :
https://forum.phpfrance.com/tutoriels/formulaires-listes-deroulantes-dynamiques-liees-t4562.html