[RESOLU] Affichage selon sélection liste

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] Affichage selon sélection liste

Re: Affichage selon sélection liste

par nico63800 » 02 déc. 2013, 16:59

il y a plusieurs solutions
voilà une base de départ avec un peu de code javascript
ce n'est peut etre pas la plus elegante car on genere des elements de formulaires qui ne serviront pas
mais elle a le mérite d'etre simple :)
cordialement

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
    <title>test</title>
</head>

<body>
<div>
	<div style="float: left; margin-right: 30px;">
		<select name="select" id="liste_deroulante" onChange="affich_radios(this);">
			<option value="">catégorie...</option>
			<option value="fiscale">FISCALE</option>
			<option value="sociale">SOCIALE</option>
			<option value="comptable">COMPTABLE</option>
			<option value="juridique">JURIDIQUE</option>
		</select>
	</div>

	<div style="float: left; display: none;" id="div_fiscale" >
		<input type="radio" name="radio_fiscal" value="fiscal_1" id="fi_1" /><label for="fi_1">fiscal choix 1</label><br />
		<input type="radio" name="radio_fiscal" value="fiscal_2" id="fi_2" /><label for="fi_2">fiscal choix 2</label><br />
		<input type="radio" name="radio_fiscal" value="fiscal_3" id="fi_3" /><label for="fi_3">fiscal choix 3</label>
	</div>

	<div style="float: left; display: none;" id="div_sociale" >
		<input type="radio" name="radio_social" value="social_1" id="so_1" /><label for="so_1">social choix 1</label><br />
		<input type="radio" name="radio_social" value="social_2" id="so_2" /><label for="so_2">social choix 2</label><br />
		<input type="radio" name="radio_social" value="social_3" id="so_3" /><label for="so_3">social choix 3</label>
	</div>

	<div style="float: left; display: none;" id="div_comptable" >
		<input type="radio" name="radio_comptable" value="comptable_1" id="co_1" /><label for="co_1">comptable choix 1</label><br />
		<input type="radio" name="radio_comptable" value="comptable_2" id="co_2" /><label for="co_2">comptable choix 2</label><br />
		<input type="radio" name="radio_comptable" value="comptable_3" id="co_3" /><label for="co_3">comptable choix 3</label>
	</div>

	<div style="float: left; display: none;" id="div_juridique" >
		<input type="radio" name="radio_juridique" value="juridique_1" id="ju_1" /><label for="ju_1">juridique choix 1</label><br />
		<input type="radio" name="radio_juridique" value="juridique_2" id="ju_2" /><label for="ju_2">juridique choix 2</label><br />
		<input type="radio" name="radio_juridique" value="juridique_3" id="ju_3" /><label for="ju_3">juridique choix 3</label>
	</div>
</div>

<script type="text/javascript">
	function affich_radios(obj)
	{
		limit = obj.options.length;
		
		// le for demarre à 1 et pas à 0
		// car la premiere ligne du select doit masquer toutes les options
		for ( i=1; i<limit; i++ )  
		{
			var div_name    = 'div_'+obj.options[i].value ;
			var div_to_show = document.getElementById(div_name);
			
			if(obj.options[i].selected)
			{
				div_to_show.style.display = "" ;
			}
			else
			{
				div_to_show.style.display = "none" ;
			}
		}
	}
</script>

</body>
</html>

Affichage selon sélection liste

par acym » 02 déc. 2013, 14:04

Bonjour,
J'ai une liste

Code : Tout sélectionner

<select name="select"> <option value="fiscale" selected="fiscale">FISCALE</option> <option value="sociale" selected="sociale">SOCIALE</option> <option value="comptable" selected="comptable">COMPTABLE</option> <option value="juridique" selected="juridique">JURIDIQUE</option> <option value="" selected=""></option> </select>
Si lutilisateur sélectionne FINANCE
cela doit faire afficher des boutons radios en rapport à cette sélection.
et ainsi de suite pour les autres sélections.
Si cela a une importance j'ai deux autres sélect dans mon fichier .
Ce que je ne sais pas faire.
C'est où mettre le IF
et quoi mettre dedans.
Merci.
fichier joint:
<div id="principale">
    <?php
    if(($_SESSION['username'] ='pierreN') XOR ($_SESSION['username'] ='raphaelle') XOR ($_SESSION['username'] ='pierre') 
        XOR ($_SESSION['username'] ='anea') XOR ($_SESSION['username'] ='christophe'))
 	{
    ?>
     <div id="ajouter">
     <center><h2> Ajouter un nouveau client </h2></center>
     <form method="post" action="mysql_add_client.php" enctype="multipart/form-data">
    <table class="label">
        <tr>
            <td>Nom Dossier</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>Type de mission</td>
            <td> 
            <select name="select">
                <option value="fiscale" selected="fiscale">FISCALE</option>
                <option value="sociale" selected="sociale">SOCIALE</option>
                <option value="comptable" selected="comptable">COMPTABLE</option>
                <option value="juridique" selected="juridique">JURIDIQUE</option>
                <option value="" selected=""></option>
            </select>
            </td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>Type Dossier</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
        </tr>
        <tr>
            <td>Collaborateur *</td>
            <td> 
            <select name="select">
                <option value="RH" selected="RH">RH</option>
                <option value="PG" selected="PG">PG</option>
                <option value="AJ" selected="AJ">AJ</option>
                <option value="CH" selected="CH">CH</option>
                <option value="" selected=""></option>
            </select>
            </td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>Date de cloture</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>Tâche</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
        </tr>
        <tr>
            <td>Périodicité</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>Date d'échéance</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>Quantité</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
        </tr>
        <tr>
            <td>Avancement</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>Commentaire</td>
            <td><input name="nom_dossier" type="text" maxlength="100" /></td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
            <td>&nbsp;&nbsp;&nbsp;</td>
        </tr>
    </table> 

   </form>



     </div><!-- End div ajouter -->
    <?php
    }
    else
    {
    ?>
    <div class="message">
Vous n'êtes pas autorisé à visiter cette page.
<br/>
Contacter l'administrateur pour créer un compte.
<br/>
Retour à l' <a href="<?php echo $url_home; ?>"> Accueil</a>
</div>
<?php
}
?>
 	<!-- fin du texte -->
Merci d'aider PAPY .