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 :

Position des fenetres input


Sujet :

JavaScript

  1. #1
    Futur Membre du Club
    Inscrit en
    Septembre 2003
    Messages
    9
    Détails du profil
    Informations forums :
    Inscription : Septembre 2003
    Messages : 9
    Points : 7
    Points
    7
    Par défaut Position des fenetres input
    Bonsoir

    Dans un petit formulaire que j ai sur mon je voudrais avoir un select qui ouvre des inputs, j ai un code qui fonctionne parfaitement, sauf que si je choisie 1 le input ce place sous la case select, si je choisi 2 alors 2 input sont bien présent sauf qui a un décalage ainsi de suite, j aimerais qui n est pas ce décalage. Voici le code en question.

    Code HTML : 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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
     
    <script language="JavaScript">
     
    function affiche_formulaire() {
    // Particulier
    if (document.votre_activite.activite.selectedIndex == 0)
    document.getElementById('form_particulier').style.visibility = 'visible';
    else
    document.getElementById('form_particulier').style.visibility = 'hidden';
     
    // Association
    if (document.votre_activite.activite.selectedIndex == 1)
    document.getElementById('form_association').style.visibility = 'visible';
    else
    document.getElementById('form_association').style.visibility = 'hidden';
     
    // Entreprise
    if (document.votre_activite.activite.selectedIndex == 2)
    document.getElementById('form_entreprise').style.visibility = 'visible';
    else
    document.getElementById('form_entreprise').style.visibility = 'hidden';
    }
    </script>
     
    </head>
     
    <body>
     
    <form name="votre_activite" action="" method="post">
     
    <label><strong>Nombre de patineur :</strong></label> <select name="activite" OnChange="affiche_formulaire();">
     
     <option value="particulier">1</option>
     <option value="association">2</option>
     <option value="entreprise"> 3</option>
                                                     </select>
        <br/>
    </form>   
     
     
    <!-- Particulier -->
    <span id="form_particulier" style="visibility:text">
     
    <form method="post" action="">
    <label><strong>Patineur 1:</strong></label> 
    <input type="text" name="nom_particulier"/><br/>
    </form></span>
     
    <!-- Association -->
     
    <span id="form_association" style="visibility:hidden">
     
    <form method="post" action="">
    <label><strong>Patineur 1:</strong></label> 
    <input type="text" name="nom_association"/><br/>      
    <label><strong>Patineur 2:</strong></label> <input type="text" name="nom_association"/><br/>
    </form></span>
     
    <!-- Entreprise -->
    <span id="form_entreprise" style="visibility:hidden">
     
    <form method="post" action="">
    <label><strong>Patineur 1:</strong></label> 
    <input type="text" name="nom_particulier"/><br/> 
    <label><strong>Patineur 2:</strong></label> 
    <input type="text" name="nom_association"/><br/>
    <label><strong>Patineur 3:</strong></label> 
    <input type="text" name="nom_entreprise"/><br/>
    </form></span>
     
    </select>
    </form>
    </body>
    </html>

    Merci beaucoup pour votre aide.

  2. #2
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2016
    Messages
    149
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 23
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2016
    Messages : 149
    Points : 252
    Points
    252
    Par défaut
    Bonjour,

    Je pense que tu ferais mieux de tous recoder, parce que cette page doit pas mal dater, non ?

  3. #3
    Expert éminent sénior
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 107
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 107
    Points : 16 630
    Points
    16 630
    Par défaut
    Salut
    Moi aussi cela ne fait pas des années que je me suis mis au HTML, sans trop transformer ton code, je te propose ce
    Code HTML : 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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    		<title>Untitled Document</title>
     
    		<script>
                            function affiche_formulaire() {
                                    // Particulier
                                    if (document.votre_activite.activite.selectedIndex == 1){
                                            document.getElementById('form_particulier').style.display = 'block';
                                            }else{
                                            document.getElementById('form_particulier').style.display = 'none';
                                    }
                                    // Association
                                    if (document.votre_activite.activite.selectedIndex == 2){
                                            document.getElementById('form_association').style.display = 'block';
                                            }else{
                                            document.getElementById('form_association').style.display = 'none';
                                    }
                                    // Entreprise
                                    if (document.votre_activite.activite.selectedIndex == 3){
                                            document.getElementById('form_entreprise').style.display = 'block';
                                            }else{
                                            document.getElementById('form_entreprise').style.display = 'none';
                                    }
                            }
                    </script>
    	</head>
     
    	<body>
     
    		<form name="votre_activite" action="" method="post">
    			<label><strong>Nombre de patineur :</strong></label>
    			<select name="activite" OnChange="affiche_formulaire();" value="">
    				<option value="" selected></option>
    				<option value="particulier">1</option>
    				<option value="association">2</option>
    				<option value="entreprise"> 3</option>
    			</select>
    			<br />
    		</form>   
     
    		<!-- Particulier -->
    		<div id="form_particulier" style="display:none">
    			<form method="post" action="">
    				<label><strong>Patineur 1:</strong></label> 
    				<input type="text" name="nom_particulier"/><br/>
    			</form>
    		</div>
     
    		<!-- Association -->
    		<div id="form_association" style="display:none">
    			<form method="post" action="">
    				<label><strong>Patineur 1:</strong></label> 
    				<input type="text" name="nom_association"/><br/>      
    				<label><strong>Patineur 2:</strong></label>
    				<input type="text" name="nom_association"/><br/>
    			</form>
    		</div>
     
    		<!-- Entreprise -->
    		<div id="form_entreprise" style="display:none">
    			<form method="post" action="">
    				<label><strong>Patineur 1:</strong></label> 
    				<input type="text" name="nom_particulier"/><br/> 
    				<label><strong>Patineur 2:</strong></label> 
    				<input type="text" name="nom_association"/><br/>
    				<label><strong>Patineur 3:</strong></label> 
    				<input type="text" name="nom_entreprise"/><br/>
    			</form>
    		</div>
    	</body>
    </html>

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    une variante au script JS :
    Code JavaScript : 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
    <script>
    function affiche_formulaire() 
    {
      // 1- on masque les 3
      document.getElementById('form_particulier').style.display = 'none';
      document.getElementById('form_association').style.display = 'none';
      document.getElementById('form_entreprise').style.display = 'none';
     
      // 2- on affiche le bon
    	if (document.votre_activite.activite.selectedIndex)
    	{
    		switch(document.votre_activite.activite.selectedIndex)
    		{
    		  case 1: // Particulier
    			document.getElementById('form_particulier').style.display = 'block';
    			break;
    		  case 2: // Association
    			document.getElementById('form_association').style.display = 'block';
    			break;
    		  case 3: // Entreprise
    			document.getElementById('form_entreprise').style.display = 'block';
    			break;
    		}
    	}
    }
    </script>
    Par contre :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <label><strong>Nombre de patineur :</strong></label> 
    <select name="activite" OnChange="affiche_formulaire();">
    	<option value="particulier">1</option>
    	<option value="association">2</option>
    	<option value="entreprise"> 3</option>
    1- Quel rapport entre "particulier/association/entreprise" et un "Nombre de patineur(s)" ???

    2- PLUS IMPORTANT : il faut écrire
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <select name="activite" onchange="affiche_formulaire();">
    	<option value="" selected="selected">...choisissez...</option>
    	<option value="1">particulier</option>
    	<option value="2">association</option>
    	<option value="3">entreprise</option>
    Dernière modification par Invité ; 21/08/2018 à 15h57.

Discussions similaires

  1. réduction/changement de position des éléments lors du recadrage de la fenetre
    Par emirdagli dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 20/11/2008, 10h58
  2. Position des input et des libelles
    Par samouille666 dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 29/12/2007, 18h46
  3. Garder Taille et positions des fenetres
    Par Cazaux-Moutou-Philippe dans le forum Mandriva / Mageia
    Réponses: 1
    Dernier message: 05/07/2007, 21h04
  4. MDI Application - position des fenetres
    Par Redsky dans le forum Delphi
    Réponses: 4
    Dernier message: 26/09/2006, 09h57
  5. [web] [PerlTk] Position des fenêtres
    Par Cyspak dans le forum Interfaces Graphiques
    Réponses: 2
    Dernier message: 05/11/2004, 11h49

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