begin process at 2012 05 29 21:36:34
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Javascript / DHTML / Ajax

 > 

CSS

 > 

Général

 > 

Problème de textbox & menu deroulant associé


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Problème de textbox & menu deroulant associé

mercredi 10 juin 2009 à 22:13:16 | Problème de textbox & menu deroulant associé

4lman78

Bonjour

J'ai deux champs texte dans l'exemple ci dessous, dans mon cas concret il pourra y en avoir une vingtaine.

Or je n'arrive pas a ce que chaque champs texte opère avec les menu déroulant lui correspondant.

Voici mon code :

<html>
<head>

<script language="javascript">
function affichechoix(texte)
{
    if (texte.value!="0") {
        for (var i=1; i<=99; i++) {
        var indice = "alex" + i;
        document.getElementById(indice).style.display= 'none';
       
        }
        for (var i=1; i<=texte.value; i++) {
        var indice = "alex" + i;
        document.getElementById(indice).style.display= 'block';
        }
    }
}
function affichelol(texte)
{
    if (texte.value!="0") {
        for (var i=1; i<=99; i++) {
        var indice = "alex" + i;
        document.getElementById(indice).style.display= 'none';
       
        }
        for (var i=1; i<=texte.value; i++) {
        var indice = "alex" + i;
        document.getElementById(indice).style.display= 'block';
        }
    }
}
</script>
</head>
<body>

<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >
<INPUT type="text" onChange="affichechoix(this)" name="triprincipal" ></INPUT>
<p><center>
    <?php   
    for ($i=1; $i<100; $i++){
    ?>
        <div id="alex<?php echo $i; ?>" style="display:none">
        <SELECT name="alex<?php echo $i; ?>" value="alex<?php echo $i; ?>">
            <OPTION VALUE="S">A</OPTION>
            <OPTION VALUE="M">B</OPTION>
            <OPTION VALUE="L">C</OPTION>
            <OPTION VALUE="XL">D</OPTION>
            <OPTION VALUE="XXL">E</OPTION>
            <OPTION VALUE="XXXL">F</OPTION>
        </SELECT></div>
    <?php
        }
    ?>       
</center>
<br />
<INPUT type="text" onChange="affichelol(this)" name="triprincipal" ></INPUT>
<p><center>
    <?php   
    for ($i=1; $i<100; $i++){
    ?>
        <div id="alex<?php echo $i; ?>" style="display:none">
        <SELECT name="alex<?php echo $i; ?>" value="alex<?php echo $i; ?>">
            <OPTION VALUE="S">F</OPTION>
            <OPTION VALUE="M">G</OPTION>
            <OPTION VALUE="L">H</OPTION>
            <OPTION VALUE="XL">I</OPTION>
            <OPTION VALUE="XXL">J</OPTION>
            <OPTION VALUE="XXXL">K</OPTION>
        </SELECT></div>
    <?php
        }
    ?>       
</center>
<br />
<input type="submit" name="go" value="Afficher les annonces" />
</form>
</body>
</html>

jeudi 11 juin 2009 à 08:17:16 | Re : Problème de textbox & menu deroulant associé

Bul3

Membre Club


Bonjour,

loin d'avoir tout compris !
mais : tu as plusieurs éléments avec le même ID, c'est interdit.
un ID doit être unique dans une page
ensuite :

__ j'ai remplacé la fonction affichechoix comme suit
function affichechoix(texte)
{   if (texte.value!="0") {
            var i=1;
            while (document.getElementById("alex" + i) )
            {    document.getElementById("alex" + i).style.display= 'none';
                 i++;
            }
            document.getElementById("alex"+texte.value).style.display= 'block';
        }
}

__ mis en commentaires la fonction affichelol

__ fait un exemple avec 2 div ( 100 c'était trop )
<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >
    <INPUT type="text" onChange="alert(this); affichechoix(this)" name="triprincipal" ></INPUT>
<p><center>
        <div id="alex1" style="display:none">
        <SELECT name="alex1" value="alex1">
            <OPTION VALUE="S">A</OPTION>
            <OPTION VALUE="M">B</OPTION>
            <OPTION VALUE="L">C</OPTION>
            <OPTION VALUE="XL">D</OPTION>
            <OPTION VALUE="XXL">E</OPTION>
            <OPTION VALUE="XXXL">F</OPTION>
        </SELECT></div>
</center>
<br />
<INPUT type="text" onChange="affichelol(this)" name="triprincipal" ></INPUT>
<p><center>
        <div id="alex2" style="display:none">
        <SELECT name="alex2" value="alex2">
            <OPTION VALUE="S">F</OPTION>
            <OPTION VALUE="M">G</OPTION>
            <OPTION VALUE="L">H</OPTION>
            <OPTION VALUE="XL">I</OPTION>
            <OPTION VALUE="XXL">J</OPTION>
            <OPTION VALUE="XXXL">K</OPTION>
        </SELECT></div>
</center>
<br />
<input type="submit" name="go" value="Afficher les annonces" />
</form>

je ne sais pas si ça correspond avec ce que tu veux ( c'est pas clair ) ??
mais ça affiche le div voulu. à toi de finir.
perso j'aurais procédé autrement :
    cacher le div précédent affiché
    montrer le div actuel
    div précédent affiché = div actuel

ça évite toutes boucles

Cordialement [mon Site] [M'écrire] Bul
jeudi 11 juin 2009 à 09:10:18 | Re : Problème de textbox & menu deroulant associé

4lman78

Alors ok pour ca merci.

Mais dans la case du text, c'est un chiffre qui est rentré, en fonction de ce nombre il faudra affiché le nombre correspondant de menu déroulant

Comment puis-je procéder avec une boucle for?

Merci
jeudi 11 juin 2009 à 09:34:42 | Re : Problème de textbox & menu deroulant associé

Bul3

Membre Club
>>c'est un chiffre qui est rentré, en fonction de ce nombre
>>il faudra affiché le nombre correspondant de menu déroulant
dans le select ?
document.form1["alex"+index].selectedIndex=Number(texte.value);
par exemple, si on passe l'index du sdelect à l'appel
passer le name ou l'id.. du select, tu peux


jeudi 11 juin 2009 à 09:46:19 | Re : Problème de textbox & menu deroulant associé

Bul3

Membre Club
enfin... s'il y a plusieurs select... ce dont je ne suis plus sûr....
jeudi 11 juin 2009 à 11:30:05 | Re : Problème de textbox & menu deroulant associé

4lman78

Alors j'ai repris les choses, comment simplifié ce code? Je présice ce code marche mais comment faire pour qu'il n'y ai qu'un seule fonction affichechoix et non affichechoix1, affichechoix2, affichechoix3

Merci d'avance !

<script language="javascript">
function affichechoix1(texte)
{
    if (texte!="0") {        
        for (var i=1; i<=20; i++) {
        var indice = "alex1";
        document.getElementById(indice).style.display= 'none';        
        }
        for (var i=1; i<=texte; i++) {
        var indice = "alex1";
        document.getElementById(indice).style.display= 'block';
        }
    }
}

function affichechoix2(texte)
{
    if (texte!="0") {        
        for (var i=1; i<=20; i++) {
        var indice = "alex2";
        document.getElementById(indice).style.display= 'none';        
        }
        for (var i=1; i<=texte; i++) {
        var indice = "alex2";
        document.getElementById(indice).style.display= 'block';
        }
    }
}

function affichechoix3(texte)
{
    if (texte!="0") {        
        for (var i=1; i<=20; i++) {
        var indice = "alex3";
        document.getElementById(indice).style.display= 'none';        
        }
        for (var i=1; i<=texte; i++) {
        var indice = "alex3";
        document.getElementById(indice).style.display= 'block';
        }
    }
}

</script>
</head>
<body>

<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >
<INPUT type="text" onChange="affichechoix1(this.value)" name="triprincipal" ></INPUT>
<p><center>
        <div id="alex1" style="display:none">
        <SELECT name="alex1" value="alex1">
            <OPTION VALUE="S">A</OPTION>
            <OPTION VALUE="M">B</OPTION>
            <OPTION VALUE="L">C</OPTION>
            <OPTION VALUE="XL">D</OPTION>
            <OPTION VALUE="XXL">E</OPTION>
            <OPTION VALUE="XXXL">F</OPTION>
        </SELECT></div>
</center>
<br />
<INPUT type="text" onChange="affichechoix2(this.value)" name="triprincipal2" ></INPUT>
<p><center>
        <div id="alex2" style="display:none">
        <SELECT name="alex2" value="alex2">
            <OPTION VALUE="S">A</OPTION>
            <OPTION VALUE="M">B</OPTION>
            <OPTION VALUE="L">C</OPTION>
            <OPTION VALUE="XL">D</OPTION>
            <OPTION VALUE="XXL">E</OPTION>
            <OPTION VALUE="XXXL">F</OPTION>
        </SELECT></div>
</center>
<br />
<INPUT type="text" onChange="affichechoix3(this.value)" name="triprincipal2" ></INPUT>
<p><center>
        <div id="alex3" style="display:none">
        <SELECT name="alex3" value="alex3">
            <OPTION VALUE="S">A</OPTION>
            <OPTION VALUE="M">B</OPTION>
            <OPTION VALUE="L">C</OPTION>
            <OPTION VALUE="XL">D</OPTION>
            <OPTION VALUE="XXL">E</OPTION>
            <OPTION VALUE="XXXL">F</OPTION>
        </SELECT></div>
</center>
<input type="submit" name="go" value="Afficher les annonces" />
jeudi 11 juin 2009 à 11:45:30 | Re : Problème de textbox & menu deroulant associé

4lman78

Voila une version comme je veux sauf que je voudrai pas avoir a écrire toute les possibilité, mais je ne sais pas comment utilisé une boucle de fonction.

<html>
<head>

<script language="javascript">
function affichechoix1(texte)
{
    if (texte.value!="0") {
        for (var i=1; i<=99; i++) {
        var indice = "alex" + i;
        document.getElementById(indice).style.display= 'none';
        
        }
        for (var i=1; i<=texte.value; i++) {
        var indice = "alex" + i;
        document.getElementById(indice).style.display= 'block';
        }
    }
}
function affichechoix2(texte)
{
    if (texte.value!="0") {
        for (var i=1; i<=99; i++) {
        var indice = "marie" + i;
        document.getElementById(indice).style.display= 'none';
        
        }
        for (var i=1; i<=texte.value; i++) {
        var indice = "marie" + i;
        document.getElementById(indice).style.display= 'block';
        }
    }
}

function affichechoix3(texte)
{
    if (texte.value!="0") {
        for (var i=1; i<=99; i++) {
        var indice = "pierre" + i;
        document.getElementById(indice).style.display= 'none';
        
        }
        for (var i=1; i<=texte.value; i++) {
        var indice = "pierre" + i;
        document.getElementById(indice).style.display= 'block';
        }
    }
}
</script>
</head>
<body>

<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >
<INPUT type="text" onChange="affichechoix1(this)" name="triprincipal" ></INPUT>
<p><center>
    <?php    
    for ($i=1; $i<100; $i++){
    ?>
        <div id="alex<?php echo $i; ?>" style="display:none">
        <SELECT name="alex<?php echo $i; ?>" value="alex<?php echo $i; ?>">
            <OPTION VALUE="S">A</OPTION>
            <OPTION VALUE="M">B</OPTION>
            <OPTION VALUE="L">C</OPTION>
            <OPTION VALUE="XL">D</OPTION>
            <OPTION VALUE="XXL">E</OPTION>
            <OPTION VALUE="XXXL">F</OPTION>
        </SELECT></div>
    <?php
        }
    ?>        
</center>
<br />
<INPUT type="text" onChange="affichechoix2(this)" name="triprincipal" ></INPUT>
<p><center>
    <?php    
    for ($i=1; $i<100; $i++){
    ?>
        <div id="marie<?php echo $i; ?>" style="display:none">
        <SELECT name="marie<?php echo $i; ?>" value="marie<?php echo $i; ?>">
            <OPTION VALUE="S">F</OPTION>
            <OPTION VALUE="M">G</OPTION>
            <OPTION VALUE="L">H</OPTION>
            <OPTION VALUE="XL">I</OPTION>
            <OPTION VALUE="XXL">J</OPTION>
            <OPTION VALUE="XXXL">K</OPTION>
        </SELECT></div>
    <?php
        }
    ?>        
</center>
<br />
<INPUT type="text" onChange="affichechoix3(this)" name="triprincipal" ></INPUT>
<p><center>
    <?php    
    for ($i=1; $i<100; $i++){
    ?>
        <div id="pierre<?php echo $i; ?>" style="display:none">
        <SELECT name="pierre<?php echo $i; ?>" value="pierre<?php echo $i; ?>">
            <OPTION VALUE="S">F</OPTION>
            <OPTION VALUE="M">G</OPTION>
            <OPTION VALUE="L">H</OPTION>
            <OPTION VALUE="XL">I</OPTION>
            <OPTION VALUE="XXL">J</OPTION>
            <OPTION VALUE="XXXL">K</OPTION>
        </SELECT></div>
    <?php
        }
    ?>        
</center>
<br />
<input type="submit" name="go" value="Afficher les annonces" />
</form>
</body>
</html>
jeudi 11 juin 2009 à 11:50:19 | Re : Problème de textbox & menu deroulant associé

Bul3

Membre Club
pas très bon le for ! on est lié au html !
et pourquoi une boucle ? et bien entendu, 1 seule fonction, ça suffit !


<body>
    <FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >
        <INPUT type="text" onChange="affichechoix(1,this.value);" name="triprincipal" ></INPUT>
        <center>
                  <SELECT name="alex1" style="display:none">
                        <OPTION VALUE="S">A</OPTION>
                        <OPTION VALUE="M">B</OPTION>
                        <OPTION VALUE="L">C</OPTION>
                        <OPTION VALUE="XL">D</OPTION>
                        <OPTION VALUE="XXL">E</OPTION>
                        <OPTION VALUE="XXXL">F</OPTION>
                  </SELECT>
        </center>
        <br />
        <INPUT     type="text" onChange="affichechoix(2,this.value);"
                    name="triprincipal2" ></INPUT>
        <center>
                  <SELECT name="alex2" style="display:none">
                        <OPTION VALUE="S">A</OPTION>
                        <OPTION VALUE="M">B</OPTION>
                        <OPTION VALUE="L">C</OPTION>
                        <OPTION VALUE="XL">D</OPTION>
                        <OPTION VALUE="XXL">E</OPTION>
                        <OPTION VALUE="XXXL">F</OPTION>
                  </SELECT>
        </center>
        <br />
        <INPUT type="text" onChange="affichechoix(3,this.value);" name="triprincipal2" ></INPUT>
        <center>
                  <SELECT name="alex3" style="display:none">
                        <OPTION VALUE="S">A</OPTION>
                        <OPTION VALUE="M">B</OPTION>
                        <OPTION VALUE="L">C</OPTION>
                        <OPTION VALUE="XL">D</OPTION>
                        <OPTION VALUE="XXL">E</OPTION>
                        <OPTION VALUE="XXXL">F</OPTION>
                  </SELECT>
        </center>
        <input type="submit" name="go" value="Afficher les annonces" />
    </form>
    <script type="text/javascript">
        var prec=document.form1.alex1;
        function affichechoix( index, texte )
        {   prec.style.display="none";
            prec=document.form1["alex"+index];
            prec.selectedIndex=Number(texte);
            prec.style.display="inline";
        }
    </script>
</body>

mais bon.... pas très "convivial" me semble-t-il ( ? )
mais bon.... on n'a sûrement pas tout en main....

jeudi 11 juin 2009 à 11:52:10 | Re : Problème de textbox & menu deroulant associé

Bul3

Membre Club
et une question : les select ont toujours les mêmes option ?
si oui, faudrait probablement n'en mettre qu'1

jeudi 11 juin 2009 à 14:29:19 | Re : Problème de textbox & menu deroulant associé

4lman78

oui ce sera toujours les même select. je vais essayer de trouver comment faire...
Merci pour tout !

1 2

Cette discussion est classée dans : texte, var, for, indice, alex


Répondre à ce message

Sujets en rapport avec ce message

boucle for [ par atchoumen ] Bonjour,Je suis actuellement en train de travailler sur l'api googleMap. J'ai un fichier xml dans lequel je rentre tous mes points et valeur. Pour l'i Demande aide Fichier Javascript [ par crunchattak59 ] bonjoursVoila je voudrais faire une belle signature dans outlookJ'ai vu que l'on pouvais faire pas ma l de chose avec javascript...Etant une bille en transformer un lien en texte [ par Jarod1980 ] Bonjour,J'aimerais savoir comment transformer un texte ou une image en lien sans utiliser la commande doRichEditCommand('CreateLink');En fait, ce que colorer du texte [ par bayeland ] Salut j'ai telecharger le code ci dessous et il marche tres bien. Le seul probleme et que je ne veux pas qu'il remplace le texte recherche qui se trou récuperer des morceau de texte / Regex [ par supers03 ] Bonjourj'aimerai récupérer les url des images dans un texte. Donc le but du script est de chercher les balises images et de ne prendre que l'url à l'i Respecter la ponctuation [ par fabiano13 ] Bonjour,J'ai créé une fonction qui formate un texte de la manière suivante :La virgule : texte,[espace] texteLe point-virgule : texte[espace];[espace] Problème pour appeler une fonction en javascript [ par Joke758 ] J'essaie d'appeler la fonction AM.PassportEncrypt.EncryptData("test1", null, "pwd", null) mais je ne sais pas pourquoi ça ne fait rien..voici ma sourc Probleme de boucle for (avec 1 element) [ par akh550 ] Bonjour à tous,J'ai un petit problème de boucle "for", la voici:for ( var n=0;n    {    if ( document.ResultForm.cellule[n].checked )        {    aler Probleme de boucle for (avec 1 element) [ par akh550 ] Bonjour à tous,J'ai un petit problème de boucle "for", la voici:for ( var n=0;n    {    if ( document.ResultForm.cellule[n].checked )        {    aler boucle for... in [ par klod06 ] Je ne comprends pas ce qui colle pas dans le code ci-dessous, qui est si simple pourtant, mais rien ne s'affiche quand je charge la page.Il s'agit de


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,544 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales