Flux rss
Collection CommentCaMarche.net
Rechercher : dans
Par : Pertinence Date Nom d'utilisateur
Statut : Non résolu

Verifier les menu deroulant en javascript

Francois, le lundi 6 novembre 2006 à 13:21:17
Bonjour a tous
jai un probleme avec mon formulaire qui en 3 menu deroulants
jaimerais verifier que les 3 menu deroulants sont bien selectionner, enfait je veux obliger le visiteur a choisir parmi les 3 menu deroulant une choix de chaque...

merci pour votre aide

<html>
<head>
<title>LUKB discution</title>
<script language="javascript"><!--
function resetStateText(theForm) {
  theForm.state.value = '';
  if (theForm.zcity_id.options.length > 1) {
    theForm.state.value = 'JS_STATE_SELECT';
  }
}

function resetzcitySelected(theForm) {
  if (theForm.zcity_id.options.length > 1) {
    theForm.state.value = 'JS_STATE_SELECT';
  }
}

function update_zcity(theForm) {
   
   var NumState = theForm.zcity_id.options.length;
            
   while(NumState > 0) {
      NumState--;
      theForm.zcity_id.options[NumState] = null;
   }

   var SelectedFirm = "";
            
   SelectedFirm = theForm.Firm.options[theForm.Firm.selectedIndex].value;
            
  if (SelectedFirm == "s.p.r.l. LUKB Belgium b.v.b.a.") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Brussels", "Brussels");
    theForm.zcity_id.options[2] = new Option("Waterloo", "Waterloo");
  }
  else if (SelectedFirm == "LUKB France S.A.S.") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Marseille", "Marseille");
    theForm.zcity_id.options[2] = new Option("Toulouse", "Toulouse");
    theForm.zcity_id.options[3] = new Option("Saumur", "Saumur");
    theForm.zcity_id.options[4] = new Option("Nanterre", "Nanterre");
    theForm.zcity_id.options[5] = new Option("Issy-Les-Moulineaux", "Issy-Les-Moulineaux");
  }
  else if (SelectedFirm == "LUKB Deutschland GmbH") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Hamburg, Nagelsweg", "Hamburg, Nagelsweg");
    theForm.zcity_id.options[2] = new Option("Hamburg, Bramfelder Str.", "Hamburg, Bramfelder Str.");
    theForm.zcity_id.options[3] = new Option("Düsseldorf", "Düsseldorf");
    theForm.zcity_id.options[4] = new Option("Köln", "Köln");
    theForm.zcity_id.options[5] = new Option("Frankfurt am Main", "Frankfurt am Main");
  }
  else if (SelectedFirm == "LUKB GmbH & Co. KG") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Dresden", "Dresden");
    theForm.zcity_id.options[2] = new Option("Leipzig", "Leipzig");
    theForm.zcity_id.options[3] = new Option("Berlin", "Berlin");
    theForm.zcity_id.options[4] = new Option("Hamburg, Nagelsweg", "Hamburg, Nagelsweg");
    theForm.zcity_id.options[5] = new Option("Stuhr", "Stuhr");
    theForm.zcity_id.options[6] = new Option("Hannover", "Hannover");
    theForm.zcity_id.options[7] = new Option("Bielefeld", "Bielefeld");
    theForm.zcity_id.options[8] = new Option("Düsseldorf", "Düsseldorf");
    theForm.zcity_id.options[9] = new Option("Dortmund", "Dortmund");
    theForm.zcity_id.options[10] = new Option("Köln", "Köln");
    theForm.zcity_id.options[11] = new Option("Frankfurt am Main", "Frankfurt am Main");
    theForm.zcity_id.options[12] = new Option("Darmstadt", "Darmstadt");
    theForm.zcity_id.options[13] = new Option("Saarbrücken", "Saarbrücken");
    theForm.zcity_id.options[14] = new Option("Stuttgart", "Stuttgart");
    theForm.zcity_id.options[15] = new Option("Freiburg", "Freiburg");
    theForm.zcity_id.options[16] = new Option("München", "München");
    theForm.zcity_id.options[17] = new Option("Augsburg", "Augsburg");
    theForm.zcity_id.options[18] = new Option("Regensburg", "Regensburg");
    theForm.zcity_id.options[19] = new Option("Bayreuth", "Bayreuth");
    theForm.zcity_id.options[20] = new Option("Erfurt", "Erfurt");
  }
  else if (SelectedFirm == "LUKB Service GmbH") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Dortmund", "Dortmund");
    theForm.zcity_id.options[2] = new Option("Köln", "Köln");
    theForm.zcity_id.options[3] = new Option("Frankfurt am Main", "Frankfurt am Main");
    theForm.zcity_id.options[4] = new Option("München", "München");
    theForm.zcity_id.options[5] = new Option("Nürnberg", "Nürnberg");
  }
  else if (SelectedFirm == "LUKB International Sales Ltd.") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Bargteheide", "Bargteheide");
    theForm.zcity_id.options[2] = new Option("Langenhagen", "Langenhagen");
    theForm.zcity_id.options[3] = new Option("Düsseldorf", "Düsseldorf");
    theForm.zcity_id.options[4] = new Option("Köln", "Köln");
    theForm.zcity_id.options[5] = new Option("Frankfurt am Main", "Frankfurt am Main");
    theForm.zcity_id.options[6] = new Option("Stuttgart", "Stuttgart");
    theForm.zcity_id.options[7] = new Option("München", "München");
  }
  else if (SelectedFirm == "LUKB International Sales Ltd.") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Dublin", "Dublin");
  }
  else if (SelectedFirm == "LUKB Italia S.p.A.") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Roma", "Roma");
    theForm.zcity_id.options[2] = new Option("Sesto San Giovanni", "Sesto San Giovanni");
    theForm.zcity_id.options[3] = new Option("Bologna", "Bologna");
  }
  else if (SelectedFirm == "LUKB Portugal") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Paço de Arcos", "Paço de Arcos");
  }
  else if (SelectedFirm == "LUKB Comunicación España, S.L.") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Barcelona", "Barcelona");
    theForm.zcity_id.options[2] = new Option("Madrid", "Madrid");
    theForm.zcity_id.options[3] = new Option("Santurce (Vizcaya)", "Santurce (Vizcaya)");
  }
  else if (SelectedFirm == "LUKB Switzerland GmbH") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Petit-Lancy", "Petit-Lancy");
    theForm.zcity_id.options[2] = new Option("Belp", "Belp");
    theForm.zcity_id.options[3] = new Option("Belp, Airport", "Belp, Airport");
    theForm.zcity_id.options[4] = new Option("Basel", "Basel");
    theForm.zcity_id.options[5] = new Option("Wallisellen", "Wallisellen");
    theForm.zcity_id.options[6] = new Option("Schlieren", "Schlieren");
    theForm.zcity_id.options[7] = new Option("St. Gallen", "St. Gallen");
  }
  else if (SelectedFirm == "LUKB Switzerland Sàrl") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Petit-Lancy", "Petit-Lancy");
  }
  else if (SelectedFirm == "LUKB Nederland B.V.") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Rijswijk", "Rijswijk");
    theForm.zcity_id.options[2] = new Option("Nieuwegein", "Nieuwegein");
  }
  else if (SelectedFirm == "LUKB UK") {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNER;?>", "WARNING!!!");
    theForm.zcity_id.options[1] = new Option("Guildford", "Guildford");
    theForm.zcity_id.options[2] = new Option("Hertfordshire", "Hertfordshire");
    theForm.zcity_id.options[3] = new Option("Manchester", "Manchester");
    theForm.zcity_id.options[4] = new Option("North Lanarkshire", "North Lanarkshire");
    theForm.zcity_id.options[5] = new Option("Uxbridge", "Uxbridge");
  }
  else {
    theForm.zcity_id.options[0] = new Option("<?php print VEUILLEZ_SELECTIONNERVILLE;?>", "WARNING!!!");
  }
   resetStateText(theForm);

}
//--></script>
</head>
<body>
<table border="0" width="100%" cellspacing="5" cellpadding="5">
    <tr>
        <td width="353" valign="top">
            <form action="registration.php" method="POST" name="form101" onsubmit="return formu()";>
                <p><input type="hidden" name="action" value="process"></p>
                <table border="0" width="100%" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="615">
                            <p><select name="Firm" onChange="update_zcity(this.form);">
<option value="WARNING!!!"><?php print SELECTIONNE_PAYS;?></option>
<option value="s.p.r.l. LUKB Belgium b.v.b.a.">s.p.r.l. LUKB Belgium b.v.b.a.</option>
<option value="LUKB France S.A.S.">LUKB France S.A.S.</option>
<option value="LUKB Deutschland GmbH">LUKB Deutschland GmbH</option>
<option value="LUKB GmbH & Co. KG">LUKB GmbH & Co. KG</option>
<option value="LUKB Service GmbH">LUKB Service GmbH</option>
<option value="LUKB International Sales Ltd.">Comergo GmbH</option>
<option value="LUKB International Sales Ltd.">LUKB International Sales Ltd.</option>
<option value="LUKB Italia S.p.A.">LUKB Italia S.p.A.</option>
<option value="LUKB Portugal">LUKB Portugal</option>
<option value="LUKB Comunicación España, S.L.">LUKB Comunicación España, S.L.</option>
<option value="LUKB Switzerland GmbH">LUKB Switzerland GmbH</option>
<option value="LUKB Switzerland Sàrl">LUKB Switzerland Sàrl</option>
<option value="LUKB Nederland B.V.">LUKB Nederland B.V.</option>
<option value="LUKB UK">LUKB UK</option>
</select>
&nbsp;</font></p>
                            <select name="zcity_id" onChange="resetStateText(this.form)";>
<option value="WARNING!!!"><?php print VEUILLEZ_SELECTIONNERVILLE;?></option>

</select>
</select>&nbsp;</font></p>
<?php 
   

    $query_select = "SELECT countries_name FROM countries ORDER BY countries_id"; 
    $req_select = mysql_query($query_select) or die('Erreur SQL !'.$query_select.'<br>'.mysql_error()); 
?> 
<select name="cpays"> 
<option value="WARNING!!!" selected><?php print PAYS;?></option> 
<?php 
     
// boucle permetant le listage des valeurs et l'affichage -----------------     
        while($select = mysql_fetch_array($req_select)) 
        { 
        echo '<option value='.$select['countries_name'].'>'.$select['countries_name'].'</option>'; 
        } 

  
        ?> 
    </select>
                       <INPUT TYPE="submit" VALUE="<?php print ENVOYER;?>"> </td>                    </tr>
 
                                                
          </table>
                
            </td>
        </tr>
</table>
</body>
</html>
Répondre à Francois  Signaler ce message aux modérateurs Aller au dernier message

1


  • Ce message vous semble utile, votez !
  • Signaler ce message aux modérateurs
Ssylvainsab, le lundi 6 novembre 2006 à 18:51:11
Bonsoir.

Est-ce que ca ne serait pas plus simple en php ?
if ((!isset($_POST['case_a_cocher_1'])) or (!isset($_POST[['case_a_cocher_2'])) or (!isset($_POST[['case_a_cocher_3'])))
   echo 'Erreur : vous n\'avez pas rempli tout les champs';

De plus, le JS est un langage client, donc modfiable par l'utilisateur qui peut en faire ce qu'il veut (et /ou le désactiver).

Si tu ne veux pas, je pense que tu pourras facilement adapter ce code en JS, les deux langages ayant une syntaxe très proche ;-)

a plus Sylvain
Répondre à Ssylvainsab

2


  • Ce message vous semble utile, votez !
  • Signaler ce message aux modérateurs
 moicjm, le mercredi 23 juillet 2008 à 17:32:42
Bonjour,

pourquoi quand je copie ton code avec isset, le serveur me renvoie "unexpected T_LOGICAL_OR " ?

En fait ca me plaisait bien ce "or", car ca me permettait de dire "si var1 est fixée ou si var2 est fixée, etc...

merci
Répondre à moicjm
[JS] Probleme de menu déroulant (Résolu) Bonjour a tous, Voilà, j'ai un souci avec un menu déroulant javascript que j'ai fait... Le menu marche très bien, avec une variable de temps pour qu'il reste ouvert un petit moment avant de se fermer, lorsqu'on fait un MouseOut...... www.commentcamarche.net/forum/affich-3488102-js-probleme-de-menu-deroulant
Problème menu déroulant javascript + CSS (Résolu) Bonjour à tous, Je suis en train de réaliser un site et j'ai réalisé un menu dont une partie est un menu déroulant. Tout marche niquel mais le problème est que lorsque le menu se déroule, mes "li" qui ont pourtant une apparence normale se... www.commentcamarche.net/forum/affich-6862393-probleme-menu-deroulant-javascript-css
Problème avec menu déroulant Javascript (Résolu) Bonjour, J'ai un petit soucis de menu déroulant comme l'indique le titre, j'ai crée un site qui fonctionne sous firefox et ie7 mais en le testant sous ie6 des problème son parvenu (Normal me diré vous :D) Donc après quelque modifs dans... www.commentcamarche.net/forum/affich-7313507-probleme-avec-menu-deroulant-javascript
Ajouter un raccourci dans le menu contextuel du poste de travailQui n'a jamais rêvé de pouvoir avoir accès en un seul clic à certaines commandes enfouies dans les menus déroulants du système ? Problématique Imaginons que nous voulions aller dans la fenêtre de gestion de l'ordinateur. 2... www.commentcamarche.net/faq/sujet-5359-ajouter-un-raccourci-dans-le-menu-contextuel-du-poste-de-travail
Google Talk - Installer GtalkGoogle dispose dans sa trousse à outils d’un programme de chat appelé Google Talk. Pour le télécharger, cliquez sur le lien « plus » dans la page d’accueil de Google, puis sur « et encore plus » dans le menu déroulant qui s’est ouvert. Dans la fenêtre... www.commentcamarche.net/faq/sujet-14923-google-talk-installer-gtalk
Google Desktop - Installer Google DesktopAvant d’utiliser le logiciel, vous devez préalablement le récupérer sur Internet. Pour cela, cliquez sur le lien « plus » visible sur le bord supérieur de la page d’accueil de Google. Dans le menu déroulant qui s’est ouvert, cliquez sur « et encore... www.commentcamarche.net/faq/sujet-14760-google-desktop-installer-google-desktop
Probleme menu déroulant explorer/firefox (Résolu)Bonjour à tous, alors voila je suis entrain de faire un site web qui contient un menu deroulant . Ca marche tres bien sous firefox mais internet explorer me pose des problemes... les menus ne se deroulent pas sous IE donc je suppose que ca vient du... www.commentcamarche.net/forum/affich-7295480-probleme-menu-deroulant-explorer-firefox
[HTML - Javascript] Menu déroulants cascade (Résolu)Bonjour, Je bosse sur un formulaire et j'aimerais que l'on puisse selectionner une valeur dans un menu déroulant et que lors de la sélection le menu déroulant suivant change de valeur Le premier menu permet de choisir une catégorie et le... www.commentcamarche.net/forum/affich-1518850-html-javascript-menu-deroulants-cascade
Menu déroulant dynamique php/mysql et ajax (Résolu)Bonjour, Alors, pour expliquer mon probleme rapidement :d J'aimerais créer un formulaire, possédant quelques menus déroulant dynamique, le second étant basé sur le premier : Par ex, on possède une interface administration, grâce a laquelle on... www.commentcamarche.net/forum/affich-8127805-menu-deroulant-dynamique-php-mysql-et-ajax
Fichier TSKFormat TSK Un fichier TSK est un thème pour Windows Mobile (Pocket PC).Un thème définit contient dans un seul fichier le fond d'écran, la couleur de la barre de menu, la couleur de la barre d'icones et le fond du menu déroulant de la page de... www.commentcamarche.net/contents/fichier/tsk.php3