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 :

Onchange + submit


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2012
    Messages : 10
    Par défaut Onchange + submit
    Bonjour,

    J'ai un soucis en javascript. En faites, je n'arrive plus à recuperer les valeurs utiliser dans le onchange apres un submit.

    Code : 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
    <?php
    echo "<head>
    <script type=\"text/javascript\">
    function updateTotal(){
    //On récupère le total
    var total=0;
    total += parseInt(document.getElementById('selRange1').innerHTML);
    total += parseInt(document.getElementById('selRange2').innerHTML);
    total += parseInt(document.getElementById('selRange3').innerHTML);
    total += parseInt(document.getElementById('selRange4').innerHTML);
    total += parseInt(document.getElementById('selRange5').innerHTML);
    total += parseInt(document.getElementById('selRange6').innerHTML);
     
    //Puis on ajoute dans la case
    document.getElementById('case_total').innerHTML=total;
    }
    </script>
    </head>";
                if ($_POST['verif'] != 1)
                {
                    echo "<form action=\"mapage.php\" method=\"post\">";
                    echo "<table cellspacing=\"0\" cellpadding=\"3px\" rules=\"rows\"  style=\"border:solid 1px #777777; border-collapse:collapse; font-family:verdana; font-size:11px; margin-left:auto; margin-right:auto;\">";
                    echo "<caption>Composition :</caption>";
                    echo "<tr style=\"background-color:lightgrey;\">";
                    echo "<th style=\"width:140px;\">Famille 1</th>";
                    echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam1\" onchange=\"document.getElementById('selRange1').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                    echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange1\">0</span> %</th>";
                echo "</tr>";
                echo "<tr style=\"background-color:lightgrey;\">";
                echo "<th style=\"width:140px;\">Famille 2</th>";
                echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam2\" onchange=\"document.getElementById('selRange2').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange2\">0</span> %</th>";
                echo "</tr>";
                echo "<tr style=\"background-color:lightgrey;\">";
                echo "<th style=\"width:140px;\">Famille 3</th>";
                echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam3\" onchange=\"document.getElementById('selRange3').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange3\">0</span> %</th>";
                echo "</tr>";
                echo "<tr style=\"background-color:lightgrey;\">";
                echo "<th style=\"width:140px;\">Famille 4</th>";
                echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam4\" onchange=\"document.getElementById('selRange4').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin: margin-left: 9%;\"><span id=\"selRange4\">0</span> %</th>";
                echo "</tr>";
                echo "<tr style=\"background-color:lightgrey;\">";
                echo "<th style=\"width:140px;\">Famille 5</th>";
                echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam5\" onchange=\"document.getElementById('selRange5').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange5\">0</span> %</th>";
                echo "</tr>";
                echo "<tr style=\"background-color:lightgrey;\">";
                echo "<th style=\"width:140px;\">Famille 6</th>";
                echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam6\" onchange=\"document.getElementById('selRange6').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange6\">0</span> %</th>";
                echo "</tr>";
                echo "</table>";
                echo "<p style=\"width:100px;\">Votre compo est remplie à: <span style=\"border: 2px solid black; margin: 0px 0px 0px 0px;\"><span id=\"case_total\">0</span> %</p>";
                echo "<input type=\"hidden\" name=\"verif\" value=\"1\">";
                echo "<input type=\"submit\" name=\"submit\" value=\"Valider votre choix\" />";
                echo "</form>";
                }
                else if ($_POST['verif'] == 1)
                echo 'valeur des compos : 1= '.$_POST['fam1'].' 2= '.$_POST['fam2'].' 3= '.$_POST['fam3'].' 4= '.$_POST['fam4'].' 5= '.$_POST['fam5'].' 6= '.$_POST['fam6'].'';
     
    ?>
    Du coup ici, toutes mes variables s'actualisent en direct, par contre, je n'arrives pas à les recuperer derriere dans le POST.
    Est ce qu'il est possible à un moment de dire que $mavariablephp = resultat de SelRange1 par exemple ?

    Bonne journée

  2. #2
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Dans un premier temps, ce serait sympa de lire Important : Les règles incontournables d'utilisation de ce forum et de poster le code HTML et JavaScript généré et non le code PHP.

    Merci de garder à l'esprit que si vous voulez être aidé, il faut donner envie aux personnes qui lisent votre message de le faire et poster un code bien présenté est un bon début.
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2012
    Messages : 10
    Par défaut
    Bonjour,

    Je suis sous joomla 1.5 et le code généré est bien celui là.

    Mon soucis concerne le lien entre le code javascript et la répercussion sur les inputs, POST et submit, j'aurai du mal du coup à poster autre chose sachant que ce n'est pas le résultat visuel qui m’intéresse mais bien le code en question...

    En essayant de faire plus clair:

    Code : 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
     <?php
    session_start();
    echo "<head>
    <script type=\"text/javascript\">
    function updateTotal(){
    //On récupère le total
    var total=0;
    total += parseInt(document.getElementById('selRange1').innerHTML);
    total += parseInt(document.getElementById('selRange2').innerHTML);
     
    //Puis on ajoute dans la case
    document.getElementById('case_total').innerHTML=total;
    }
    </script>
    </head>";
                            if ($_POST['verif'] != 1)
                            {
                                    echo "<form action=\"mapage.php\" method=\"post\">";
                                    echo "<table cellspacing=\"0\" cellpadding=\"3px\" rules=\"rows\"  style=\"border:solid 1px #777777; border-collapse:collapse; font-family:verdana; font-size:11px; margin-left:auto; margin-right:auto;\">";
                                    echo "<caption>Composition :</caption>";
                                    echo "<tr style=\"background-color:lightgrey;\">";
                                    echo "<th style=\"width:140px;\">Famille 1</th>";
                                    echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam1\" onchange=\"document.getElementById('selRange1').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                                    echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange1\">0</span> %</th>";
                            echo "</tr>";
                            echo "<tr style=\"background-color:lightgrey;\">";
                            echo "<th style=\"width:140px;\">Famille 2</th>";
                            echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam2\" onchange=\"document.getElementById('selRange2').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
                            echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange2\">0</span> %</th>";
                            echo "</tr>";
                            echo "</table>";
                            echo "<p style=\"width:100px;\">Votre compo est remplie à: <span style=\"border: 2px solid black; margin: 0px 0px 0px 0px;\"><span id=\"case_total\">0</span> %</p>";
                            echo "<input type=\"hidden\" name=\"verif\" value=\"1\">";
                            echo "<input type=\"submit\" name=\"submit\" value=\"Valider votre choix\" />";
                            echo "</form>";
                            }
                            else if ($_POST['verif'] == 1)
                            {
                                    echo 'valeur des compos : 1= '.$_POST['fam1'].' 2= '.$_POST['fam2'].' ';
                                    print_r($_POST);
                            }
    ?>

  4. #4
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 659
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 659
    Billets dans le blog
    1
    Par défaut
    visiblement tu n'as pas lu :
    Dans un premier temps, ce serait sympa de lire Important : Les règles incontournables d'utilisation de ce forum et de poster le code HTML et JavaScript généré et non le code PHP.
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  5. #5
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2012
    Messages : 10
    Par défaut
    Si j'ai bien lu,

    Je ne comprends juste pas l'intêret dans mon cas de retirer tous les echos de mon code sachant que justement c'est le lien qui m'interesse non ?

    EDIT: voilà le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    function updateTotal(){
    //On récupère le total
    var total=0;
    total += parseInt(document.getElementById('selRange1').innerHTML);
    total += parseInt(document.getElementById('selRange2').innerHTML);
     
    //Puis on ajoute dans la case
    document.getElementById('case_total').innerHTML=total;
    }
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
    <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: verif in E:\epitech\logiciel\WampServer\wamp\www\session\mapage.php on line <i>16</i></th></tr>
    <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
    <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
    <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>373104</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='E:\epitech\logiciel\WampServer\wamp\www\session\mapage.php' bgcolor='#eeeeec'>..\mapage.php<b>:</b>0</td></tr>
    </table></font>
    <form action="mapage.php" method="post"><table cellspacing="0" cellpadding="3px" rules="rows"  style="border:solid 1px #777777; border-collapse:collapse; font-family:verdana; font-size:11px; margin-left:auto; margin-right:auto;"><caption>Composition :</caption><tr style="background-color:lightgrey;"><th style="width:140px;">Famille 1</th><th> <input type="range" style="margin-left: 15%; name="fam1" onchange="document.getElementById('selRange1').innerHTML = this.value; updateTotal();" value="0" step="5" max="100" min="0"></input></th><th style="width:50px;"><span style="border: 2px solid black; margin-left: 9%;"><span id="selRange1">0</span> %</th></tr><tr style="background-color:lightgrey;"><th style="width:140px;">Famille 2</th><th> <input type="range" style="margin-left: 15%; name="fam2" onchange="document.getElementById('selRange2').innerHTML = this.value; updateTotal();" value="0" step="5" max="100" min="0"></input></th><th style="width:50px;"><span style="border: 2px solid black; margin-left: 9%;"><span id="selRange2">0</span> %</th></tr></table><p style="width:100px;">Votre compo est remplie à: <span style="border: 2px solid black; margin: 0px 0px 0px 0px;"><span id="case_total">0</span> %</p><input type="hidden" name="verif" value="1"><input type="submit" name="submit" value="Valider votre choix" /></form>

  6. #6
    Membre Expert
    Avatar de Kaamo
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    1 165
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 165
    Par défaut
    Donc c'est un problème PHP.
    Le code généré = afficher le code source grâce à un navigateur internet

    Si tu veux passer les valeurs de selRangeX au serveur (php), il faut utiliser le formulaire. Donc, à l'aide d'un input et non d'un span comme tu le fais

  7. #7
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2012
    Messages : 10
    Par défaut
    Ok, j'avais mal compris le "code généré", autant pour moi ...

    En faites, c'est pas exactement ce que je souhaite faire. Je souhaite juste recuprer les valeurs des ranges de fam1 et fam2 (ce qui reviens au même vous direz) sauf que ceux là sont déjà dans des inputs

  8. #8
    Membre Expert
    Avatar de Kaamo
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    1 165
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 165
    Par défaut
    Voilà pourquoi il faut afficher le code généré Que nous montre t il ?
    Vu la coloration syntaxique, il manque une quote " pour fermer l'attribut style au niveau de "fam1" (et ça a l'air d'être pareil pour les autres)

    De plus, tu as un warning apparemment :
    Notice: Undefined index: verif in E:\epitech\logiciel\WampServer\wamp\www\session\mapage.php on line <i>16</i>
    Règle n°1 : toujours regarder l'état du code grâce aux outils développeurs qui l'analysent (F12 Chrome / IE 10. Ctrl + Shift + K ou Firebug pour Firefox)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 28
    Dernier message: 10/08/2010, 12h01
  2. [firefox] onchange submit ne fonctionne pas
    Par nicerico dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 23/09/2008, 17h27
  3. [MySQL] Liste déroulante : onchange="submit();"
    Par zabuze dans le forum PHP & Base de données
    Réponses: 12
    Dernier message: 02/06/2007, 18h38
  4. textarea onchange et bouton submit
    Par VVE dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 01/02/2006, 14h00
  5. onChange="this.form.submit();" marche pas sous IE
    Par Death83 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 25/09/2005, 11h05

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