Verifier les menu deroulant en javascript

Fermé
Francois - 6 nov. 2006 à 13:21
 moicjm - 23 juil. 2008 à 17:32
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>
A voir également:

2 réponses

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
0
Ssylvainsab Messages postés 2884 Date d'inscription samedi 29 juillet 2006 Statut Modérateur Dernière intervention 15 août 2020 825
6 nov. 2006 à 18:51
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
-1