[RESOLU] recupérer valeur liste deroulante sur la même page

sabine45
Invité n'ayant pas de compte PHPfrance

16 mai 2006, 15:41

Bon la premiere marche ça m'affiche bien les enregistrement dans le tableau, par contre la liste deroulante s'initialise. Et se met sur choissisez, vous savez d'ou cela vient ?
merci

Modérateur PHPfrance
Modérateur PHPfrance | 2575 Messages

16 mai 2006, 15:50

Je viens de lire ton code et compris ce que tu veux faire :
je t'ai déjà conseillé d'utiliser un submit dans onChange, je reconfirme mais pour que ta requête prenne en compte le matricule sélectionné il faut ajouter dans le where une condition qui lui correspond.

Voici, un corrigé de ton code qui charge la 2° requête selon le matricule choisi dans la liste et tout ce passe sur la même page.
Sans oublier de rappeler à l'utilisateur le matricule déjà choisi bien sûr.
<html> 
<head> 

<title>Les grands comptes</title> 
<script language="javascript"> 
function choisir(truc, truc2, truc3, truc4) 
{ 
window.opener.document.enreg.mat.value= truc; 
window.opener.document.enreg.gc.value= truc2; 

self.close();} 

</script> 
<style type="text/css"> 
<!-- 
.Style1 {font-family: Tahoma} 
--> 
</style> 
</head> 
<body> 

<span class="Style1"> 
<?php 

include_once("connexion.php"); 
   
?> 

</span> 
<p align="left" class="Style1">&nbsp;</p> 
<form name="enreg" method="GET" > 
<?php 
$Req = mysql_query("SELECT nom_gc, matricule_gc FROM grand_compte where nom_gc<>''ORDER BY nom_gc"); 

//Le nom de la liste est matgc, onChange le matricule sera envoyé dans $_GET["matgc"]
$ld = "<SELECT NAME='matgc' onChange='enreg.submit();'>"; 
$ld .= "<OPTION VALUE=0>Choisissez</OPTION>"; 
// On boucle sur la table 
// + sélectionner l'option déjà choisie
while ( $row = mysql_fetch_array($Req)) { 
    $nom = $row["nom_gc"]; 
    $mat = $row["matricule_gc"]; 
    $option_selected = ($_GET["matgc"] && $mat == $_GET["matgc"]) ? " SELECTED " : "";
    $ld .= "<OPTION VALUE='$mat'  $option_selected>$nom</OPTION>"; 
} 
$ld .= "</SELECT>"; 

?> 
</form> 
<?php 

if ($_GET["matgc"]) { ?> 
<p align="left" class="Style1">&nbsp;    </p> 
<p class="Style1"></p> 
<p class="Style1"></p> 
<table width="100%"  border="1"> 
  <tr align="center" valign="middle"> 
    <td width="9%" class="Style1">Matricule du site </td> 
    <td width="17%" class="Style1">Adresse</td> 
    <td width="6%" class="Style1">Code postal </td> 
    <td width="21%" class="Style1">Ville</td> 
  </tr> 
<?php 

// on crée la requête SQL 
//+ Filtrage par matgc reçu de la liste des matricules
$reqsql2 = mysql_query("SELECT `lieux`.`matricule_lieux`, `lieux`.`ad_rue_lieux`, `cp_ville`, `ville`, `nom_gc`, lieux.site 
from `lieux`, `ville`, `grand_compte` 
where `grand_compte`.`matricule_gc`=`lieux`.`matricule_gc` 
and `lieux`.`code_ville`=`ville`.`code_ville` 
and `lieux`.`matricule_gc`='$grcpt' order by `ville`
and `grand_compte`.`matricule_gc` = '$_GET[matgc]'
"); 

while ($rep = @mysql_fetch_object($reqsql2)) { 
            $mat = $rep->matricule_lieux; 
            $ad = $rep->ad_rue_lieux; 
            $cp = $rep->cp_ville; 
            $vil = $rep->ville; 
            $gc = $rep->nom_gc; 
              $sit= $rep->site; 
?> 
   
  <tr align="center" valign="middle"> 
   
    <td class="Style1"><a href="#" onClick="javascript:choisir('<?php echo $mat; ?>' , '<?php echo $gc; ?>' , '<?php echo $ad." ".$cp." ".$vil ?>', '<?php echo $sit; ?>' )" ><?php echo $mat; ?></a></td> 
    <td class="Style1"><?php echo $ad ?></td> 
    <td class="Style1"><?php echo $cp ?></td> 
    <td class="Style1"><?php echo $vil ?></td> 
  </tr> 

<?php 
} 
?> 
</table> 
<?php 
} 
?> 
<div align="center" class="Style1"></div> 
</body> 
</html>
--------//////----//---//----//////
-------//---//----//---//----//---//
------//////----//////-----//////
-----||--------||--||---||
Prendre le recul n'est pas une perte de temps.


ps: Affrontez moi dans l'arène

sabine45
Invité n'ayant pas de compte PHPfrance

16 mai 2006, 15:56

j'ai essayé avec ton code, mais ça ne maffiche rien du tout, j'ai une page blanche, avec le code modifier grace a vos commentaires j'ai plus que le probleme avec la liste deroulante qui se reinitialise.
onChange=\"document.location.href='grcpt2.php?matgc=' + this.options[this.selectedIndex].value;\">"; 

timide
Invité n'ayant pas de compte PHPfrance

16 mai 2006, 16:17

Si tu utilise sa:
onChange="document.location.href='grcpt2.php?matgc=' + this.options[this.selectedIndex].value;\">";
$option_selected = ($_GET["matgc"] && $mat == $_GET["matgc"]) ? " SELECTED " : "";
 
par ça:
$option_selected = ($_REQUEST["matgc"] && $mat == $_REQUEST["matgc"]) ? " SELECTED " : "";
Et je pense que ça doit marcher!

Modérateur PHPfrance
Modérateur PHPfrance | 2575 Messages

16 mai 2006, 16:41

j'ai essayé avec ton code, mais ça ne maffiche rien du tout, j'ai une page blanche, avec le code modifier grace a vos commentaires j'ai plus que le probleme avec la liste deroulante qui se reinitialise.
onChange="document.location.href='grcpt2.php?matgc=' + this.options[this.selectedIndex].value;">"; 
J'ai effacé par erreur un print ($ld), tu dois pouvoir le remettre à sa place.

Ou bien je te le fait, tiens :
<html> 
<head> 

<title>Les grands comptes</title> 
<script language="javascript"> 
function choisir(truc, truc2, truc3, truc4) 
{ 
window.opener.document.enreg.mat.value= truc; 
window.opener.document.enreg.gc.value= truc2; 

self.close();} 

</script> 
<style type="text/css"> 
<!-- 
.Style1 {font-family: Tahoma} 
--> 
</style> 
</head> 
<body> 

<span class="Style1"> 
<?php 

include_once("connexion.php"); 
    
?> 

</span> 
<p align="left" class="Style1">&nbsp;</p> 
<form name="enreg" method="GET" > 
<?php 
$Req = mysql_query("SELECT nom_gc, matricule_gc FROM grand_compte where nom_gc<>''ORDER BY nom_gc"); 

//Le nom de la liste est matgc, onChange le matricule sera envoyé dans $_GET["matgc"] 
$ld = "<SELECT NAME='matgc' onChange='enreg.submit();'>"; 
$ld .= "<OPTION VALUE=0>Choisissez</OPTION>"; 
// On boucle sur la table 
// + sélectionner l'option déjà choisie 
while ( $row = mysql_fetch_array($Req)) { 
    $nom = $row["nom_gc"]; 
    $mat = $row["matricule_gc"]; 
    $option_selected = ($_GET["matgc"] && $mat == $_GET["matgc"]) ? " SELECTED " : ""; 
    $ld .= "<OPTION VALUE='$mat'  $option_selected>$nom</OPTION>"; 
} 
$ld .= "</SELECT>"; 

//Afficher la liste
print ($ld);
?> 
</form> 
<?php 

if ($_GET["matgc"]) { ?> 
<p align="left" class="Style1">&nbsp;    </p> 
<p class="Style1"></p> 
<p class="Style1"></p> 
<table width="100%"  border="1"> 
  <tr align="center" valign="middle"> 
    <td width="9%" class="Style1">Matricule du site </td> 
    <td width="17%" class="Style1">Adresse</td> 
    <td width="6%" class="Style1">Code postal </td> 
    <td width="21%" class="Style1">Ville</td> 
  </tr> 
<?php 

// on crée la requête SQL 
//+ Filtrage par matgc reçu de la liste des matricules 
$reqsql2 = mysql_query("SELECT `lieux`.`matricule_lieux`, `lieux`.`ad_rue_lieux`, `cp_ville`, `ville`, `nom_gc`, lieux.site 
from `lieux`, `ville`, `grand_compte` 
where `grand_compte`.`matricule_gc`=`lieux`.`matricule_gc` 
and `lieux`.`code_ville`=`ville`.`code_ville` 
and `lieux`.`matricule_gc`='$grcpt' order by `ville` 
and `grand_compte`.`matricule_gc` = '$_GET[matgc]' 
"); 

while ($rep = @mysql_fetch_object($reqsql2)) { 
            $mat = $rep->matricule_lieux; 
            $ad = $rep->ad_rue_lieux; 
            $cp = $rep->cp_ville; 
            $vil = $rep->ville; 
            $gc = $rep->nom_gc; 
              $sit= $rep->site; 
?> 
    
  <tr align="center" valign="middle"> 
    
    <td class="Style1"><a href="#" onClick="javascript:choisir('<?php echo $mat; ?>' , '<?php echo $gc; ?>' , '<?php echo $ad." ".$cp." ".$vil ?>', '<?php echo $sit; ?>' )" ><?php echo $mat; ?></a></td> 
    <td class="Style1"><?php echo $ad ?></td> 
    <td class="Style1"><?php echo $cp ?></td> 
    <td class="Style1"><?php echo $vil ?></td> 
  </tr> 

<?php 
} 
?> 
</table> 
<?php 
} 
?> 
<div align="center" class="Style1"></div> 
</body> 
</html>
Modifié en dernier par sadeq le 16 mai 2006, 16:46, modifié 1 fois.
--------//////----//---//----//////
-------//---//----//---//----//---//
------//////----//////-----//////
-----||--------||--||---||
Prendre le recul n'est pas une perte de temps.


ps: Affrontez moi dans l'arène

sabine45
Invité n'ayant pas de compte PHPfrance

16 mai 2006, 16:45

en effet, ça marche.
merci à tous


bonne fin de journée

Invité
Invité n'ayant pas de compte PHPfrance

28 juil. 2006, 01:49

Tu fait un script en Java Script
du style
<SCRIPT LANGUAGE="JavaScript">function ChangeValeur(formulaire){ ... }</SCRIPT>
Puis dans ton select
<select size="1" onChange="ChangeValeur(this.form)" name="Liste">
Voilà ... apres tu met ce que tu veux .... et grâce à ta fonction en JavaScript, tu récupere ta valeur et tu l'envoie pour affichage

:)