HTML = Liste déroulante + actualisation !

Bonjour tout le monde,

Voila j'ai un soucis avec des listes déroulante, Je veux que si je fais un choix dans une liste (remplie a l'aide d'une base de donnée), une deuxième liste s'actualise en fonction du premier choix!

Voici mon code pour mes Deux listes :

	 <select name="select" title="<?php echo $row_Recordset2['Libelle_Famille']; ?>">
  	   <?php
		do {  
		?>
  	  <option value="<?php echo $row_Recordset2['Libelle_Famille']?>"><?php echo $row_Recordset2['Libelle_Famille']?></option>
  	   <?php
		} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  	$rows = mysql_num_rows($Recordset2);
  	if($rows > 0) {
      mysql_data_seek($Recordset2, 0);
	  $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  		}?>
     </select>
  	 


	 <select name="select" title="<?php echo $row_Recordset1['Code_Article']; ?>">
  	   <?php
		do {  
		?>
 	  <option value="<?php echo $row_Recordset1['Code_Article']?>"<?php if (!(strcmp($row_Recordset1['Code_Article'], $row_Recordset1['Code_Article']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['Code_Article']?></option>
	    <?php
		} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
	$rows = mysql_num_rows($Recordset1);
	if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  		}?>
  	</select>


Donc dans mon premier "select " je voudrais rajouter une procédure OnChange pour mettre a jour la deuxième liste.

Merci d'avance de vous intéresser a mon problème!

8 réponses

  1. Je l'ai retrouvé !!

    <html>
    <!-- Date de création: 24/12/2003 -->
    <head>
    <title>menus deroulants liés</title>
    <SCRIPT LANGUAGE="JavaScript">
    menu=new Array()
    // Rajoutez un élément au tableau menu pour chaque categorie supplémentaire
    // De la même façon, pensez à modifier le formulaire pour rajouter des categories.
    menu[0]=new Array()
    menu[1]=new Array()
    menu[2]=new Array()
    menu[3]=new Array()
    menu[4]=new Array()
    menu[5]=new Array()
    menu[6]=new Array()
    menu[7]=new Array()
    // Modifiez ici les variables pour les menus deroulant
    menu[0][0]=new Option("1")
    menu[1][0]=new Option("2")
    menu[2][0]=new Option("3")
    menu[3][0]=new Option("4")
    menu[4][0]=new Option("5")
    menu[5][0]=new Option("6")
    menu[6][0]=new Option("7")
    menu[7][0]=new Option("8")
    // Ne rien modifier sous cette ligne
    function changeSousTheme(numeroMenu){
    for (i=document.menuDeroulant.sousTheme.options.length-1;i>0;i--){
    document.menuDeroulant.sousTheme.options[i]=null
    }
    for (i=0;i<menu[numeroMenu].length;i++){
    document.menuDeroulant.sousTheme.options[i]=new Option(menu[numeroMenu][i].text,menu[numeroMenu][i].value)
    }
    document.menuDeroulant.sousTheme.selectedIndex=0
    }
    function selectmenu(theme_prin){
    if (theme_prin.theme.options[theme_prin.theme.selectedIndex].value == "null"){
    alert('selectionnez d\'abord une personne');
    }
    else{
    window.top.location.href = theme_prin.theme.options[theme_prin.theme.selectedIndex].value;
    }
    }
    function destination(){
    var destination = document.menuDeroulant.sousTheme.options[document.menuDeroulant.sousTheme.selectedIndex].value;
    if(destination=="null"){
    alert('Veuillez saisir une destination valide!');
    }
    else{
    window.top.location.href = destination;
    }
    }
    </SCRIPT>
    </head>
    <body>
    <FORM NAME="menuDeroulant">
    <SELECT NAME="theme" SIZE=1 onChange="selectmenu(this.form)">
    <OPTION selected VALUE="null">-=Prénom=-</option>
    <OPTION VALUE="Javascript:changeSousTheme(0)">François</option>
    <OPTION VALUE="Javascript:changeSousTheme(1)">Eric </option>
    <OPTION VALUE="Javascript:changeSousTheme(2)">Marie-Laure</option>
    <OPTION VALUE="Javascript:changeSousTheme(3)">Christophe</option>
    <OPTION VALUE="Javascript:changeSousTheme(4)">Stéphane</option>
    <OPTION VALUE="Javascript:changeSousTheme(5)">Eric</option>
    <OPTION VALUE="Javascript:changeSousTheme(6)">Patrick</option>
    <OPTION VALUE="Javascript:changeSousTheme(7)">Alexandre</option>
    </SELECT>
    <br>
    numero
    <SELECT NAME="sousTheme">
    <OPTION VALUE="null">num</option>
    </SELECT>
    <input type="reset" value="Effacer">
    </FORM>
    </body>
    </html>

    Essaye et dis moi si c'est ce que tu cherchais.
    1. salut
      j'ai eu le meme probleme un jour,
      j'avais trouvé quelqu'un qui avait une bonne combine.Il appelait ca un "combo-select".
      je crois l'avoir vu sur code-source. com ou .fr.

      Dsl de pas faire plus.
      Charly
      1. pas de code-source.fr et pas non plus de code-source.com

        Tu n'aurai pas le code de ton boulot que tu avais fait?
        1. C'est exactement ça que je veux mais avec mon exemple précis donc pour adapter ça avec mon code cela ne va pas etre le plus simple!!!
          1. salut Charly25 , ton code est magnifique mais il ne fonctionne que dans du html, et j'ai besoin de récupérer les valeurs dans une requète mysql donc avec du php. dès que j'ajoute <?php ?> rien ne va plus.
            As tu une solution?
            Cordialement lolo
            1. Salut,
              Première remarque: tu as mis le même nom pour tes deux listes
              Essayes ou inspires de toi de ce code, je ne l'ai pas testé, il reste peut être des erreurs de frappe.

              J'ai simplifié l'affichage par la boucle while, j'ai aussi enlevé le title= dans la balise select, je ne l'ai pas vu nulle part dans les préconisations ?

              j'ai nommé ce script page1.php, si tu changes de nom change dans <form action=" "

              le:<?php if($_POST['select1']==$row_Recordset2['Libelle_Famille']{echo "selected";})?>
              sert à garder la selection de la liste 1 lorsque la page se recharge.

              <form name="part1" method="post" action="page1.php">
              Libelle_Famille<br>
              <select name="select1"  onChange="Submit()">
               <?php
              		while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)) {  
              		?>
                	  <option value="<?php echo $row_Recordset2['Libelle_Famille']?>" <?php if($_POST['select1']==$row_Recordset2['Libelle_Famille']{echo "selected";})?>><?php echo $row_Recordset2['Libelle_Famille']?></option>
              <?php
              		} 
              ?>
                   </select>
               </form>
              <br>
              <?php
              if(isset($_POST['select1'] && $_POST['select1']!="") {
              	$selection_liste1=$_POST['select1'];
              	//tu utilises cette valeur pour ta requette  qui va alimenter la liste 2
              
              ?> 
              	<form name="part2" method="post" action="page1.php"> 
              		<!-- on passe en champ caché la valeur selectionnee en liste un pour le traitement futur -->
              		<input type="hidden" name="select_liste1"value="<?php echo $_POST['select1'] ?>"> 
              Code_Article<br>
              		<select name="select2" >
               <?php
              		while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) {  
              ?>
              		<option value="<?php echo $row_Recordset1['Code_Article']?>"<?php if (!(strcmp($row_Recordset1['Code_Article'], $row_Recordset1['Code_Article']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['Code_Article']?></option>
              <?php
              		}
              ?>
              		</select>
              		<input type="submit" name="envoyer" value="Envoyer"> <!-- bouton pour la suite  il va poster la valeur selectionnee de la liste 2 et en champ cahe celle de la liste1-->
              	</form>
              
              <?php
              }
              
              /* pour la suite:
              
              tu fais
               if(isset($_POST['envoyer'] && $_POST['envoyer']!="") {
              tu recuperes les valeurs
              
              $_POST['select_liste1']
              $_POST['select2']
              
              etc...
              
              }
              
              
              */
              ?>
              1. Bonjour à tous,

                j'ai un gros soucis avec Axis, pour les services Web. En effet, j'ai une application qui tournait très bien. Je dois rajouter dessus un service web pour communiquer avec une autre application. Pour celà, je suis allé télécharger le axis.jar, l'activation.jar, et les options: mail.jar.

                axis est installé sur le répertoire suivant: C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis
                et le fichier d'activation + les options sous:C:\MesDocuments\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis\WEB-INF\lib\activation.jar.

                j'ai redémarré Tomcat 5.5 et lancé une nouvelle page et clicquer sur validation pas de soucis, la page m'affichait

                Axis Happiness Page

                Examining webapp configuration
                Language: [en] [ja]
                Needed Components
                • Found SAAJ API ( javax.xml.soap.SOAPMessage ) at C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis\WEB-INF\lib\saaj.jar

                • Found JAX-RPC API ( javax.xml.rpc.Service ) at C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis\WEB-INF\lib\jaxrpc.jar

                • Found Apache-Axis ( org.apache.axis.transport.http.AxisServlet ) at C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis\WEB-INF\lib\axis.jar

                • Found Jakarta-Commons Discovery ( org.apache.commons.discovery.Resource ) at C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis\WEB-INF\lib\commons-discovery-0.2.jar

                • Found Jakarta-Commons Logging ( org.apache.commons.logging.Log ) at C:\Borland\JBuilder2006\thirdparty\jakarta-tomcat-5.5.9\bin\commons-logging-api.jar

                • Found Log4j ( org.apache.log4j.Layout ) at C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis\WEB-INF\lib\log4j-1.2.8.jar

                • Found IBM's WSDL4Java ( com.ibm.wsdl.factory.WSDLFactoryImpl ) at C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\webapps\axis\WEB-INF\lib\wsdl4j-1.5.1.jar

                Le gros gros soucis que j'ai, c'est que mon application ne se lance plus et j'ai l'erreur suivant:

                C:\Borland\JBuilder2006\jdk1.5\bin\javaw -classpath "C:\Borland\JBuilder2006\thirdparty\jakarta-tomcat-5.5.9\bin\bootstrap.jar;C:\Borland\JBuilder2006\jdk1.5\lib\tools.jar" "-Dcatalina.home=C:/Borland/JBuilder2006/thirdparty/jakarta-tomcat-5.5.9" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=291H0V:2413,suspend=y org.apache.catalina.startup.Bootstrap -config "C:\Mes Documents\jbproject\MauManager\MAUMANAGER\Tomcat\conf\server8080.xml" start
                5 déc. 2007 14:48:48 org.apache.coyote.http11.Http11Protocol init
                INFO: Initialisation de Coyote HTTP/1.1 sur http-8080
                5 déc. 2007 14:48:48 org.apache.catalina.startup.Catalina load
                INFO: Initialization processed in 843 ms
                5 déc. 2007 14:48:48 org.apache.catalina.core.StandardService start
                INFO: Démarrage du service Catalina
                5 déc. 2007 14:48:48 org.apache.catalina.core.StandardEngine start
                INFO: Starting Servlet Engine: Apache Tomcat/5.5.9
                5 déc. 2007 14:48:48 org.apache.catalina.core.StandardHost start
                INFO: XML validation disabled
                5 déc. 2007 14:48:49 org.apache.catalina.realm.JAASRealm setContainer
                INFO: Set JAAS app name Catalina
                5 déc. 2007 14:48:50 org.apache.coyote.http11.Http11Protocol start
                INFO: Démarrage de Coyote HTTP/1.1 sur http-8080
                5 déc. 2007 14:48:50 org.apache.catalina.startup.Catalina start
                INFO: Server startup in 2485 ms
                5 déc. 2007 14:48:51 org.apache.axis.configuration.EngineConfigurationFactoryFinder newFactory
                ATTENTION: Factory org.apache.axis.configuration.EngineConfigurationFactoryServlet Ignored: missing required method: public static EngineConfigurationFactory newFactory(Object).
                5 déc. 2007 14:48:51 org.apache.axis.configuration.EngineConfigurationFactoryFinder newFactory
                ATTENTION: Factory org.apache.axis.configuration.EngineConfigurationFactoryDefault Ignored: missing required method: public static EngineConfigurationFactory newFactory(Object).
                5 déc. 2007 14:48:51 org.apache.axis.configuration.EngineConfigurationFactoryFinder$1 run
                GRAVE: Unable to locate a valid EngineConfigurationFactory
                5 déc. 2007 14:48:51 org.apache.struts.action.RequestProcessor processException
                ATTENTION: Unhandled Exception thrown: class java.lang.NullPointerException
                5 déc. 2007 14:48:51 org.apache.catalina.core.StandardWrapperValve invoke
                GRAVE: "Servlet.service()" pour la servlet action a généré une exception
                java.lang.NullPointerException
                at org.apache.axis.client.Service.getEngineConfiguration(Service.java:812)
                at org.apache.axis.client.Service.getAxisClient(Service.java:103)
                at org.apache.axis.client.Service.<init>(Service.java:112)
                at com.geodis.portal.mau.generated.UserSessionFactoryServiceLocator.<init>(UserSessionFactoryServiceLocator.java:12)
                at com.geodis.portal.mau.client.UserSessionWSClient.<init>(UserSessionWSClient.java:22)
                at com.geodis.portal.mau.web.actions.LoginAction.createUserSession(LoginAction.java:101)
                at com.geodis.portal.mau.web.actions.LoginAction.execute(LoginAction.java:45)
                at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
                at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
                at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
                at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
                at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
                at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
                at java.lang.Thread.run(Thread.java:595)

                j'arrive plus à acceder à ma page de login!!!!, pouvez vous m'aider au moins pour récuper mon application. Je travaille sous Jbulder

                Merci d'avance à tous

                Louis