Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript
JavaScript Forum programmation JavaScript. Lire : Cours JavaScript, FAQ JavaScript, Toutes les FAQ JavaScript et Sources JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 09/02/2011, 14h35   #1
Nouveau Membre du Club
 
Avatar de caro71ol
 
caroline
Étudiant
Inscription : janvier 2011
Messages : 140
Détails du profil
Informations personnelles :
Nom : caroline
Âge : 20

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 140
Points : 28
Points : 28
Par défaut verifier qu'il y a une selection

Bonjour
J'ai regardé plusieurs forums, aides diverses.

Je voudrais verifier q'une selection, d'une liste deroulante, a été faite avant d'envoyer les données au fichier php.



Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
	function modifacti(){
			var xhr = getXhr();
			var idactivite=document.formulaire.activite3.options[document.formulaire.activite3.
selectedIndex].value;
			if(idactivite==''){
				alert('Selectionnez une activite du jour!');
			}
			else
			{			
				var chacti=document.formulaire.choixacti1.options[document.formulaire.choixacti1.
selectedIndex].value;
 
 
				if(chacti==''){
					alert('Selectionnez  une activite dans l\'autre liste!');
				}
				else{
					xhr.open("POST","modifactiv.php",false);
					xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					xhr.send("idActivite="+idactivite+"&chActi="+chacti);
					var rep= xhr.responseText;
					alert(rep);
				}
			}			
	}
caro71ol est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/02/2011, 14h59   #2
Expert Confirmé Sénior
 
Avatar de RomainVALERI
 
Homme Romain VALERI
POOête
Inscription : avril 2008
Messages : 2 572
Détails du profil
Informations personnelles :
Nom : Homme Romain VALERI
Âge : 35
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : POOête

Informations forums :
Inscription : avril 2008
Messages : 2 572
Points : 4 073
Points : 4 073
Ca dépend aussi des valeurs des options de ton select : montre-nous le passage HTML correspondant (sans PHP, code généré uniquement stp ^^)
__________________

...pour les linguistes et les curieux >>> générateur de phrases aléatoires

__________________
RomainVALERI est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/02/2011, 15h26   #3
Nouveau Membre du Club
 
Avatar de caro71ol
 
caroline
Étudiant
Inscription : janvier 2011
Messages : 140
Détails du profil
Informations personnelles :
Nom : caroline
Âge : 20

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 140
Points : 28
Points : 28
formulaire:
Code :
<form method="post" action="modifplanning.php" name="formu_modif">
1ere liste:
Code :
1
2
3
4
5
6
7
	echo "<select id='activite3' name='activite11' size='8' style='font-size:20'   style='width: 300px' onchange=' goaddvisi()'>";
 
...
 
		while($row = mysql_fetch_assoc($res)){
			echo "<option value='".$row["num_planning"]."'>".$row["libelle_activite"]."&nbsp-&nbsp".$row["heuredebact"]."</option>";
		}
2eme liste:
Code :
1
2
3
4
5
6
7
8
	<select name='choixacti1' id='choixacti'  size="6" style="font-size:20" style="width: 200px" >
<?php
$res = mysql_query("SELECT * FROM activite")
			or die ('Erreur sql!'.$res.'<br/>'.mysql_error());
		while($row = mysql_fetch_assoc($res)){
			echo "<option value='".$row["numero_activite"]."'>".$row["libelle_activite"]."</option>";
		}
		?>	</select>
bouton:
Code :
		<input type="submit" name="modifier[act]" id="modifact" value="Modifier Nom de l'activité" style="height:50px;font-size:18px" onclick="modifacti();">
désolé il y a du php
caro71ol est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/02/2011, 16h06   #4
Nouveau Membre du Club
 
Avatar de caro71ol
 
caroline
Étudiant
Inscription : janvier 2011
Messages : 140
Détails du profil
Informations personnelles :
Nom : caroline
Âge : 20

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 140
Points : 28
Points : 28
j'ai tenté ceci mais po de réaction

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function modifacti(){
			var xhr = getXhr();
			if(document.getElementById('activite3').selectedIndex == '-1'){
				alert('Selectionnez une activite du jour!');
			}
			else
			{			
 
				if(document.getElementById('choixacti').selectedIndex == '-1'){
					alert('Selectionnez  une activite dans l\'autre liste!');
				}
				else{
					var sel = document.getElementById('activite3');
					var idactivite=sel.options[sel.selectedIndex].value;
					var sel2 = document.getElementById('choixacti');
					var idactivite=sel2.options[sel2.selectedIndex].value;
					xhr.open("POST","modifactiv.php",false);
					xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					xhr.send("idActivite="+idactivite+"&chActi="+chacti);
					var rep= xhr.responseText;
					alert(rep);
				}
			}			
	}
caro71ol est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/02/2011, 19h29   #5
Rédacteur/Modérateur
 
Avatar de andry.aime
 
Homme Andry Aimé
Inscription : septembre 2007
Messages : 5 126
Détails du profil
Informations personnelles :
Nom : Homme Andry Aimé
Localisation : Ile Maurice

Informations forums :
Inscription : septembre 2007
Messages : 5 126
Points : 7 270
Points : 7 270
Code :
if(document.getElementById('activite3').selectedIndex == 0)
andry.aime est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 09/02/2011, 20h52   #6
Expert Confirmé Sénior
 
Avatar de RomainVALERI
 
Homme Romain VALERI
POOête
Inscription : avril 2008
Messages : 2 572
Détails du profil
Informations personnelles :
Nom : Homme Romain VALERI
Âge : 35
Localisation : France, Meurthe et Moselle (Lorraine)

Informations professionnelles :
Activité : POOête

Informations forums :
Inscription : avril 2008
Messages : 2 572
Points : 4 073
Points : 4 073
Citation:
Envoyé par caro71ol Voir le message
désolé il y a du php
page ouverte dans le navigateur > clic droit > voir la source

A part ça, +1 andry
__________________

...pour les linguistes et les curieux >>> générateur de phrases aléatoires

__________________
RomainVALERI est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/02/2011, 22h10   #7
Rédacteur/Modérateur
 
Avatar de andry.aime
 
Homme Andry Aimé
Inscription : septembre 2007
Messages : 5 126
Détails du profil
Informations personnelles :
Nom : Homme Andry Aimé
Localisation : Ile Maurice

Informations forums :
Inscription : septembre 2007
Messages : 5 126
Points : 7 270
Points : 7 270
+1 Romain
Citation:
var sel = document.getElementById('activite3');
var idactivite=sel.options[sel.selectedIndex].value;
var sel2 = document.getElementById('choixacti');
var idactivite=sel2.options[sel2.selectedIndex].value;
andry.aime est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2011, 08h41   #8
Nouveau Membre du Club
 
Avatar de caro71ol
 
caroline
Étudiant
Inscription : janvier 2011
Messages : 140
Détails du profil
Informations personnelles :
Nom : caroline
Âge : 20

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 140
Points : 28
Points : 28
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function modifacti(){
			var xhr = getXhr();
			if(document.getElementById('activite3').selectedIndex == 0){
				alert('Selectionnez une activite du jour!');
			}
			else
			{			
 
				if(document.getElementById('choixacti').selectedIndex == 0){
					alert('Selectionnez  une activite dans l\'autre liste!');
				}
				else{
					var sel = document.getElementById('activite3');
					var idactivite=sel.options[sel.selectedIndex].value;
					var sel2 = document.getElementById('choixacti');
					var chacti=sel2.options[sel2.selectedIndex].value;
					xhr.open("POST","modifactiv.php",false);
					xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					xhr.send("idActivite="+idactivite+"&chActi="+chacti);
					var rep= xhr.responseText;
					alert(rep);
				}
			}			
	}
Code :
1
2
3
4
5
6
7
8
        <DIV id="Content" name="Content">
		 		<b>Selectionnez une <font color="red">activité du jour</font> et une activité dans la <font color="blue">liste </font>ci-dessous, puis cliquez sur Modifier :</b><br><br>
				<u><font color="blue">Liste </font>des Activités :</u><br><br><!--liste deroulante choix activité-->
	<select name='choixacti1' id='choixacti'  size="6" style="font-size:20" style="width: 200px" >
<option value='1'>Aquastretching</option><option value='2'>Aquagym</option><option value='3'>Aquabody</option><option value='4'>Aquafitness</option><option value='5'>Aquabuilding</option><option value='6'>Aquaboxing</option>	</select>
		<br><br>
		<input type="submit" name="modifier[act]" id="modifact" value="Modifier Nom de l'activité" style="height:50px;font-size:18px" onclick="modifacti();">
</DIV>
cela m'affiche ca quand il y a les 2 selections de faites :

caro71ol est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2011, 16h03   #9
Rédacteur/Modérateur
 
Avatar de andry.aime
 
Homme Andry Aimé
Inscription : septembre 2007
Messages : 5 126
Détails du profil
Informations personnelles :
Nom : Homme Andry Aimé
Localisation : Ile Maurice

Informations forums :
Inscription : septembre 2007
Messages : 5 126
Points : 7 270
Points : 7 270
Code :
1
2
3
4
5
6
7
8
function test(id){
 var lst=document.getElementById(id).options;
	for(var i=0;i<lst.length;i++){
		if(lst[i].selected)
			return true; 
	}
	return false;
}
Code html :
1
2
3
if(!test('activite3')){
				alert('Selectionnez une activite du jour!');
			}
andry.aime est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2011, 16h24   #10
Nouveau Membre du Club
 
Avatar de caro71ol
 
caroline
Étudiant
Inscription : janvier 2011
Messages : 140
Détails du profil
Informations personnelles :
Nom : caroline
Âge : 20

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 140
Points : 28
Points : 28
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
			function test(id){
 var lst=document.getElementById(id).options;
	for(var i=0;i<lst.length;i++){
		if(lst[i].selected)
			return true; 
	}
	return false;
}
 
function modifacti(){
			var xhr = getXhr();
			if(!test('jour')){
				alert('Selectionnez un jour!');
				return false;
			}
			 if(!test('activite3')){
					alert('Selectionnez une activite du jour!');
					return false;
				}
					if(!test('choixacti')){
						alert('Selectionnez une activite dans l\'autre liste!');
						return false;
					}
					else
					{
						var sel = document.getElementById('activite3');
						var idactivite=sel.options[sel.selectedIndex].value;
						var sel2 = document.getElementById('choixacti');
						var chacti=sel2.options[sel2.selectedIndex].value;
						xhr.open("POST","modifactiv.php",false);
						xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
						xhr.send("idActivite="+idactivite+"&chActi="+chacti);
						var rep= xhr.responseText;
						alert(rep);
						return true;
					}
 
 
	}
voilà au final et cela fonctionne nikel, vais pouvoir corriger pour le reste du coup.

merci à vous.
caro71ol est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 06h23.


 
 
 
 
Partenaires

Hébergement Web