Verif d'un select multiple... un coup de pouce svp ;-)

nougitch Messages postés 431 Date d'inscription mercredi 22 octobre 2003 Statut Membre Dernière intervention 17 novembre 2008 - 7 avril 2005 à 15:47
GhislainLavoie Messages postés 289 Date d'inscription vendredi 11 mars 2005 Statut Membre Dernière intervention 3 avril 2008 - 8 avril 2005 à 00:23
Bonjour,



Je voudrais vérifier que quelque chose a été selctionné dans mon select multiple.



Au départ, j'en avais fait un simple :

<select name="langues_applications">

Et avec ce script :

if(champ.langues_applications.value == 0) {

alert('Error : you didn\'t select the application\'s languages !');

return(false);

}

Cela fonctionnait parfaitement.



Mais depuis que je veux récupérer mes données dans un array et que mon select est devenu :

<select name="langues_applications[]"

Ca marche pô !



J'ai essayé avec ceci :

if(champ.langues_applications.checked[] == false) {

alert('Error : you didn\'t select the application\'s languages !');

return(false);

}

Mais rien...



Merci beaucoup pour votre aide !

1 réponse

GhislainLavoie Messages postés 289 Date d'inscription vendredi 11 mars 2005 Statut Membre Dernière intervention 3 avril 2008 3
8 avril 2005 à 00:23
Salut

Il faut faire un boucle pour voir si au moin un des éléments a été selectionés.

Exemple :


<html>
<head>
<title>Untitled</title>

<script type= "text/javascript">

function valider
(champ
)
{

for
(i
=0;i
<champ
.elements
["langues_applications[]"].length;i
++)

if
(champ
.elements
["langues_applications[]"][i
].selected
)
break;

if
(champ
.elements
["langues_applications[]"].length
i
)
{
alert
('Error
: you didn\'t select the application\'s languages
!'
);

return(false);

}

}

</script>
</head>

<form>
<select name =
"langues_applications[]" size=
4 multiple>
<option> 1</option>
<option> 2</option>
<option> 3</option>
<option> 4</option>
</select>

</form>

</html>

A+, Ghislain
0
Rejoignez-nous