submit dans un lien

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 : submit dans un lien

par alcofribas » 18 nov. 2005, 17:57

Bon, le problème change. Je reçois maintenant le message d'erreur suivant:
Error: document.forms.accords.elements.reference.submit is not a function
Line: 4
:?

par alcofribas » 17 nov. 2005, 11:02

Merci beaucoup. J'essaie ça. :)
Mais je crois que tu surestimes beaucoup mes capacités en javascritp... Je commence à savoir manipuler php et mysql, mais js c'est encore hésitant ...

par Cyrano » 16 nov. 2005, 22:59

Autant pour moi, un oubli, mais tu aurais pu (du?) le voir : un conflit entre apostrophes: corrigé:
<script type="text/javascript">
<!--
function choix(lettre)
{
    document.forms['accords'].elements['reference'].value=lettre;
    document.forms['accords'].submit();
}
-->
</script>
<tr>
<form method="post" action="accords.php" id="accords">     
        <td colspan="1" rowspan="1" style="width: 100%; vertical-align: middle; text-align: justify; font-family: Arial; font-weight: bold; color: rgb(255, 255, 255);">
                <span style="color: rgb(255, 255, 255); font-weight: bold;"><small>
                <div style="margin-left: 10px;">
                <a href="accords.php" OnClick="choix('A');">A -</a>
                <a href="accords.php" OnClick="choix('B');">B -</a>
                <a href="accords.php" OnClick="choix('C');">C -</a>
                <a href="accords.php" OnClick="choix('D');">D -</a>
                <a href="accords.php" OnClick="choix('E');">E -</a>
                <a href="accords.php" OnClick="choix('F');">F -</a>
                <a href="accords.php" OnClick="choix('G');">G -</a>
                <a href="accords.php" OnClick="choix('H');">H -</a>
                <a href="accords.php" OnClick="choix('I');">I -</a>
                <a href="accords.php" OnClick="choix('J');">J -</a>
                <a href="accords.php" OnClick="choix('K');">K -</a>
                <a href="accords.php" OnClick="choix('L');">L -</a>
                <a href="accords.php" OnClick="choix('M');">M -</a>
                <a href="accords.php" OnClick="choix('N');">N -</a>
                <a href="accords.php" OnClick="choix('O');">O -</a>
                <a href="accords.php" OnClick="choix('P');">P -</a>
                <a href="accords.php" OnClick="choix('Q');">Q -</a>
                <a href="accords.php" OnClick="choix('R');">R -</a>
                <a href="accords.php" OnClick="choix('S');">S -</a>
                <a href="accords.php" OnClick="choix('T');">T -</a>
                <a href="accords.php" OnClick="choix('U');">U -</a>
                <a href="accords.php" OnClick="choix('V');">V -</a>
                <a href="accords.php" OnClick="choix('W');">W -</a>
                <a href="accords.php" OnClick="choix('X');">X -</a>
                <a href="accords.php" OnClick="choix('Y');">Y -</a>
                <a href="accords.php" OnClick="choix('Z');">Z</a>
                <br>
                <input type="hidden" value="" name="reference" id="reference">
                </div>
                </small>
                </span>
        </td>
</tr>
<?php
      include_once('mets.php');
?>

par Invité » 16 nov. 2005, 17:52

Après passage à javascript inspector, j'ai un message d'erreur sous cette forme:
choix( syntaxe error
avec ...et une petite flèche qui indique choix(
??? :?

par alcofribas » 15 nov. 2005, 13:19

Tu as raison.
En fait, lorsque je clique sur une des lettre-lien, la liste déroulante ne s'affiche pas.
Est-ce mon script php qui est en cause? NB je l'ai placé dans le html aussi. Dois-je le mettre aux côtés du javascript, avant le <header>?

par Cyrano » 15 nov. 2005, 00:30

"lettre" est le paramètre envoyé à la fonction lors de l'appel et se trouve donc entre les parenthèses;

Tu peux mettre cette fonction dans la partie en-tête de ta page donc juste avant </head> : elle sera donc disponible dès l'affichage de la page.

Si tu utilises Firefox, va chercher l'extension webDevelopper sur le site de Firefox : une fois installée, tu verras à droite de la barre des liens pour la console JavaScript, ça t'aidera considérablement pour débugguer le JavaScript. D'autant plus que juste me dire "Ça ne marche pas" ne m'est pas d'une grande utilité pour t'aider à trouver la solution.

par alcofribas » 14 nov. 2005, 22:55

Merci beauucoup, mais ça ne fonctionne toujours pas. Je crois que je ne comprends pas cette partie de ton code:
value=lettre

Comment ce value est-il renseigné?
Autre question: dois-je placer le script avant le html ou dedans?

par Cyrano » 14 nov. 2005, 22:32

Proposition (à tester):
<script type="text/javascript">
<!-- 
function choix(lettre)
{
    document.forms['accords'].id['reference'].value=lettre;
    document.forms['accords'].submit();
}
 -->
</script>
<tr>
<form method="post" action="accords.php" id="accords">     
        <td colspan="1" rowspan="1" style="width: 100%; vertical-align: middle; text-align: justify; font-family: Arial; font-weight: bold; color: rgb(255, 255, 255);">
                <span style="color: rgb(255, 255, 255); font-weight: bold;"><small>
                <div style="margin-left: 10px;">
                <a href="accords.php" OnClick='choix('A');'>A -</a>
                <a href="accords.php" OnClick='choix('B');'>B -</a>
                <a href="accords.php" OnClick='choix('C');'>C -</a>
                <a href="accords.php" OnClick='choix('D');'>D -</a>
                <a href="accords.php" OnClick='choix('E');'>E -</a>
                <a href="accords.php" OnClick='choix('F');'>F -</a>
                <a href="accords.php" OnClick='choix('G');'>G -</a>
                <a href="accords.php" OnClick='choix('H');'>H -</a>
                <a href="accords.php" OnClick='choix('I');'>I -</a>
                <a href="accords.php" OnClick='choix('J');'>J -</a>
                <a href="accords.php" OnClick='choix('K');'>K -</a>
                <a href="accords.php" OnClick='choix('L');'>L -</a>
                <a href="accords.php" OnClick='choix('M');'>M -</a>
                <a href="accords.php" OnClick='choix('N');'>N -</a>
                <a href="accords.php" OnClick='choix('O');'>O -</a>
                <a href="accords.php" OnClick='choix('P');'>P -</a>
                <a href="accords.php" OnClick='choix('Q');'>Q -</a>
                <a href="accords.php" OnClick='choix('R');'>R -</a>
                <a href="accords.php" OnClick='choix('S');'>S -</a>
                <a href="accords.php" OnClick='choix('T');'>T -</a>
                <a href="accords.php" OnClick='choix('U');'>U -</a>
                <a href="accords.php" OnClick='choix('V');'>V -</a>
                <a href="accords.php" OnClick='choix('W');'>W -</a>
                <a href="accords.php" OnClick='choix('X');'>X -</a>
                <a href="accords.php" OnClick='choix('Y');'>Y -</a>
                <a href="accords.php" OnClick='choix('Z');'>Z</a>
                <br>
                <input type="hidden" value="" name="reference" id="reference">
                </div>
                </small>
                </span>
        </td>
</tr>
<?php
      include_once('mets.php');
?>
Explication: au lieu d'avoir 26 champs cachés ayant tous le même nom en plus, je n'en ai qu'un seul, mais j'utilise l'évènement onclick pour appeler une fonction à laquelle j'envoie la bonne lettre en paramètre: la fonction va alimenter la valeur du champ caché unique (ajouté en dessous des liens) et déclencher le submit() ensuite.

submit dans un lien

par alcofribas » 14 nov. 2005, 21:56

Bonjour,

J'ai créé une liste alphabétique toute bête où chaque lettre est un lien et un champs caché ayant pour valeur la lettre choisie.
Je voudrais que le click envoie cette valeur par submit, et je crois que je dois utiliser javascript pour cela.
Ensuite, la valeur envoyée doit être récupérée pour une requête en base de données, dont les résultats doivent s'afficher dans une liste <option...> Ouf !
J'ai essayé ça mais je n'arrive pas à faire récupérer cette valeur dans ma liste:

Code : Tout sélectionner

<tr> <form method="post" action="accords.php" id="accords"> <td colspan="1" rowspan="1" style="width: 100%; vertical-align: middle; text-align: justify; font-family: Arial; font-weight: bold; color: rgb(255, 255, 255);"> <span style="color: rgb(255, 255, 255); font-weight: bold;"><small> <div style="margin-left: 10px;"> <a href="accords.php" OnClick='submit()'><input type="hidden" value="A" name="reference">A -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="B" name="reference">B -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="C" name="reference">C -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="D" name="reference">D -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="E" name="reference">E -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="F" name="reference">F -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="G" name="reference">G -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="H" name="reference">H -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="I" name="reference">I -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="J" name="reference">J -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="K" name="reference">K -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="L" name="reference">L -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="M" name="reference">M -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="N" name="reference">N -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="O" name="reference">O -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="P" name="reference">P -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="Q" name="reference">Q -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="R" name="reference">R -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="S" name="reference">S -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="T" name="reference">T -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="U" name="reference">U -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="V" name="reference">V -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="W" name="reference">W -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="X" name="reference">X -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="Y" name="reference">Y -</a> <a href="accords.php" OnClick='submit()'><input type="hidden" value="Z" name="reference">Z</a> <br> </div> </small> </span> </td> </tr> <?php include_once('mets.php'); ?>
Voici ce que contient mets.php:
<?php

require("connect_accords.php");

if(isset($_POST['accords'])){

        $alpha = $_POST["reference"];

        if (!$alfa){

                echo '<tr>
                        <td>
                        </form>
                        </td>
                        
                </tr>';
                
        } else {
        
                $req = mysql_query('SELECT mets FROM Accords WHERE mets LIKE"'.$alpha.'%"');

                        while($result = mysql_fetch_array($req)){
                                echo '<tr>
                                        <td>
                                        <select name="met">
                                        <option value='.$result.'>
                                        </select>
                                        </form>
                                        </td>
                                </tr>';
                        }
                }
}
?>