Problème de textbox & menu deroulant associé

4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010 - 10 juin 2009 à 22:13
4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010 - 15 juin 2009 à 14:11
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>

<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >

<center>
    <?php   
    for ($i =1; $i<100; $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>

    <?php
        }
    ?>       
</center>


<center>
    <?php   
    for ($i =1; $i<100; $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>

    <?php
        }
    ?>       
</center>

</form>

</html>

11 réponses

Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
11 juin 2009 à 08:17
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" >
   
<center>
       

        <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>

</center>


<center>
       

        <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>

</center>

</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
0
4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010
11 juin 2009 à 09:10
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
0
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
11 juin 2009 à 09:34
>>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
0
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
11 juin 2009 à 09:46
enfin... s'il y a plusieurs select... ce dont je ne suis plus sûr....
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010
11 juin 2009 à 11:30
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>

<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >

<center>
       

        <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>

</center>


<center>
       

        <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>

</center>


<center>
       

        <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>

</center>
0
4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010
11 juin 2009 à 11:45
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>

<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >

<center>
    <?php    
    for ($i =1; $i<100; $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>

    <?php
        }
    ?>        
</center>


<center>
    <?php    
    for ($i =1; $i<100; $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>

    <?php
        }
    ?>        
</center>


<center>
    <?php    
    for ($i =1; $i<100; $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>

    <?php
        }
    ?>        
</center>

</form>

</html>
0
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
11 juin 2009 à 11:50
pas très bon le for ! on est lié au html !
et pourquoi une boucle ? et bien entendu, 1 seule fonction, ça suffit !

    <FORM ACTION= "/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >
       
        <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>
       

       
        <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>
       

       
        <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>
       
    </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>

mais bon.... pas très "convivial" me semble-t-il ( ? )
mais bon.... on n'a sûrement pas tout en main....
0
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
11 juin 2009 à 11:52
et une question : les select ont toujours les mêmes option ?
si oui, faudrait probablement n'en mettre qu'1
0
4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010
11 juin 2009 à 14:29
oui ce sera toujours les même select. je vais essayer de trouver comment faire...

Merci pour tout !
0
4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010
11 juin 2009 à 14:44
Pour faire une synthèse de tout :

Il y a plusieurs champs texte dans laquelle doit apparaitre une valeur numérique : 1,2,3,4....

La valeur renseigné dans ce champ texte affiche le nombre de menu déroulant a afficher.

Chaque menu déroulant est le même :

        <SELECT name="menu" value="menu">
            <OPTION VALUE="S">S</OPTION>
            <OPTION VALUE="M">M</OPTION>
            <OPTION VALUE="L">L</OPTION>
            <OPTION VALUE="XL">XL</OPTION>
            <OPTION VALUE="XXL">XXL</OPTION>
            <OPTION VALUE="XXXL">XXXL</OPTION>
        </SELECT>

Si le champs texte a la valeur 0 aucun menu déroulant doit etre affiché.

Exemple :

1er champs texte : valeur rentrée : 3 on aura donc 3 menu déroulant avec les 6 options chacun.
2er champs texte : valeur rentrée : 5 on aura donc 5 menu déroulant avec les 6 options chacun.
3er champs texte : valeur rentrée : 0 on aura donc 0 menu déroulant avec les 6 options chacun.
4er champs texte : ....

Toujours pareil, le nombre maximum de champ texte est de 50.

Je pense vous avoir remis sur la voie !!

Merci à tous pour votre aide !
0
4lman78 Messages postés 44 Date d'inscription jeudi 19 octobre 2006 Statut Membre Dernière intervention 9 février 2010
15 juin 2009 à 14:11
Voila la solution :

<html>
<head>

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

<FORM ACTION="/prive/petite_annonce/affiche_annonce.php" method="post" name="form1" >

<center>
    <?php   
    for ($i =1; $i<100; $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>

    <?php
        }
    ?>       
</center>


<center>
    <?php   
    for ($i =1; $i<100; $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>

    <?php
        }
    ?>       
</center>


<center>
    <?php   
    for ($i =1; $i<100; $i++){
    ?>
       
" style="display:none">
        <SELECT name="pierre<?php echo $i; ?>" value="marie<?php echo $i; ?>">
            <OPTION VALUE="S">L</OPTION>
            <OPTION VALUE="M">M</OPTION>
            <OPTION VALUE="L">N</OPTION>
            <OPTION VALUE="XL">O</OPTION>
            <OPTION VALUE="XXL">P</OPTION>
            <OPTION VALUE="XXXL">Q</OPTION>
        </SELECT>

    <?php
        }
    ?>       
</center>

</form>

</html>

Dans son cadre final :

http://www.poussieresdepistes.com/page/comand.php?product_partenaire=POUSSIERES%20DE%20PISTES
0
Rejoignez-nous