Page 1 sur 1

aide pour select

Posté : 14 oct. 2009, 00:44
par andri
Salut,
avant tout je tient a vous dire que je suis vraiment dans mes début dans le codage donc merci pour votre aide.
je veut faire une select et selon le choix , elle me redirige vers la page spécifier.
j'ai écrit se code:

Code : Tout sélectionner

<script language="javascript"> function action(){ window.location.replace("http://www.choix1.html"); window.location.replace("http://www.choix1.html"); } </script> <select name="dmc" onchange="action()"> <option value="Choix 1" selected>Choix 1</option> <option value="Choix 2">Choix 2</option> </select>
je bloque sur la fonction action ,comment je fait le test : si le choix1 a été sélectionné , je redirige vers la page choix1 si non je redirige vers choix2 ?
merci énormément

Re: aide pour select

Posté : 14 oct. 2009, 03:01
par sadeq
<script language="javascript">
function action(choix){
  if (choix == "") alert ('Vous devez sélectionner un choix valide!');
  else if (choix == "Choix 1")  window.location.replace("http://www.choix1.html");
         else window.location.replace("http://www.choix1.html");
}
</script>


<select name="dmc" onchange="action(this.value)">
  <option value=""></option>
  <option value="Choix 1">Choix 1</option>
  <option value="Choix 2">Choix 2</option>
</select>