[javascript] afficher div selon <select>

Résolu/Fermé
Utilisateur anonyme - 1 sept. 2008 à 11:47
Dev24 Messages postés 1 Date d'inscription mardi 27 mai 2014 Statut Membre Dernière intervention 27 mai 2014 - 27 mai 2014 à 14:02
Bonjour,
je suis en train de créer un site de covoiturage pour mon village et j'ai un probleme dans le formulaire de publication
pour afficher un div selon le choix d'un select
voila le formulaire:

<select name="type">
       <option value="Hebdomadaire">Hebdomadaire</option>	   
	   <option value="Mensuel">Mensuel</option>	
	   <option value="Unique">Unique</option>	
	   <option value="Quotidien">Quotidien</option>		   		   
	   </select><br/>
	   
	   <div id ="hebdomadaire">
	   <select name="frequence" id="hebdomadaire_liste">
       <option value="Lundi">Lundi</option>	   
	   <option value="Mardi">Mardi</option>	
	   <option value="Mercredi">Mercredi</option>	
	   <option value="Jeudi">Jeudi</option>	
	   <option value="Vendredi">Vendredi</option>	
	   <option value="Samedi">Samedi</option>	
	   <option value="Dimanche">Dimanche</option>		   
	   </select>
	   </div>
	   
	   <div id="mensuel">
       <select name="frequence">
       <option value="1">1</option>	   
	   <option value="2">2</option>	
	   <option value="3">3</option>	
	   <option value="4">4</option>	
	   <option value="5">5</option>	
	   <option value="6">6</option>	
	   <option value="7">7</option>	
	   </select>fois par mois<br/>
	   </div>
	   
	  
	   <div id="quotidien">
	   <input type="checkbox" name="Lundi" />Lundi
	   <input type="checkbox" name="Mardi" />Mardi
	   <input type="checkbox" name="Mercredi" />Mercredi
	   <input type="checkbox" name="Jeudi" />Jeudi
	   <input type="checkbox" name="Vendredi" />Vendredi
	   <input type="checkbox" name="Samedi" />Samedi
	   <input type="checkbox" name="Dimanche" />Dimanche<br/>
	   
	   </div>


je voudrai que si l'utilisateur selectionne hebdomadaire javascript afffiche la div ayant pour id hebdomadaire

merci d'avance a ceux qui me répondront

bye

13 réponses

gigaga Messages postés 2346 Date d'inscription vendredi 20 juin 2008 Statut Membre Dernière intervention 22 août 2014 301
1 sept. 2008 à 11:51
déclare <div id="hebdomadaire">
en <div id="hebdomadaire" style="display:none">

Ensuite <select name="type">
devient <select id="type" name="type" onchange="changementType();">

Créé la fonction javascript changementType qui sera un truc du genre :
function changementType() {
var type = document.getElementById("type");
var div = document.getElementById("hebdomadaire");
if (type == "hebdomadaire") {
div.style="display:block";
} else {
div.style="display:none";
}
}
10
Bonjour à tous et merci pour ce fil.

Voilà j'ai essayé d'adapter la solution proposée à mon cas c'est à dire :
Iframes devant s'afficher selon un select.
Avec le code ci-dessous cela fonctionne parfaitement du moment que l'on exerce un choix dans le select.
Par contre, cela ne fonctionne pas en arrivant sur la page. Le form affiche bien "euros" par défaut mais par contre les deux iframes sont visibles ainsi que les deux Iframes !! Normal puique le javascript n'a pas été sollicité.

Tout redevient normal lorsque justement on fait une selection dans le form et ,là, le javascript entre en action.

Auriez-vous une idée lumineuse qui résolverait mon problème ?

Je vous remercie par avance pour votre aide.
Pascal

le code :
<div id="tarif">
<Form>
<select name="type" id="type" onchange="changementType();">
<option value="Euros">Euros</option>
<option value="GBP">GBP</option>
</select>
</Form>

<script language="javascript">
function changementType() {
var type = document.getElementById("type").value;
if (type == "Euros") {
document.getElementById("Euros").style.display="block";
} else{
document.getElementById("Euros").style.display="none";
}
if (type == "GBP"){
document.getElementById("GBP").style.display="block";
}else{
document.getElementById("GBP").style.display="none";
}
}
</script>

<iframe id="Euros" src="https://sheet.zoho.com/publishrange.do?id=f836c5afc53f51a6f1b3cd9558401d38" style="height: 300px; width: 900px;" marginwidth="0" marginheight="0" padding="auto" frameborder="0" scrolling="no"> </iframe>

<iframe id="GBP" src="https://sheet.zoho.com/publishrange.do?id=e2db64ef2215f65b6aa5776caf03cd66" style="height: 300px; width: 900px;" marginwidth="0" marginheight="0" padding="auto" frameborder="0" scrolling="no"> </iframe>
</div>
2
Bonjour tout le monde, je viens de lire cette conversation même si elle a l'air terminer depuis longtemps, voila j'ai le même problème que TheGunnerKiller selon le choix fait dans une select, la div doit differer, j'ai suivi toute vos remarque sur cette conversation, mais cela ne marche pas...quelqu'un pourrait-il m'aider a trouver mon erreur?
<script type="text/javascript">
function changementType() 
{

var type = document.getElementById("type").value;


if (type == "1") 
{
document.getElementById("1").style="display:block";
} 
else
{
document.getElementById("1").style="display:none";
}


if (type == "2")
{
document.getElementById("2").style="display:block";
}
else
{
document.getElementById("2").style="display:none";
}



if (type == "Boston")
{
document.getElementById("Boston").style="display:block";
}
else
{
document.getElementById("Boston").style="display:none";
}


if (type == "Mexico")
{
document.getElementById("Mexico").style="display:block";
}
else
{
document.getElementById("Mexico").style="display:none";
}


if (type == "Ottawa")
{
document.getElementById("Ottawa").style="display:block";
}
else
{
document.getElementById("Ottawa").style="display:none";
}


if (type == "Quito")
{
document.getElementById("Quito").style="display:block";
}
else
{
document.getElementById("Quito").style="display:none";
}


if (type == "Londre")
{
document.getElementById("Londre").style="display:block";
}
else
{
document.getElementById("Londre").style="display:none";
}


if (type == "Paris")
{
document.getElementById("Paris").style="display:block";
}
else
{
document.getElementById("Paris").style="display:none";
}


if (type == "Prague")
{
document.getElementById("Prague").style="display:block";
}
else
{
document.getElementById("Prague").style="display:none";
}


if (type == "Rome")
{
document.getElementById("Rome").style="display:block";
}
else
{
document.getElementById("Rome").style="display:none";
}


}
</script>

Ca c'est ma fonction javascript

<tr>
<td>Salle </td>
<td>
<SELECT name="type" id="type" onchange="changementType();">
<OPTION value="1">Salle de réunion n°1 - RDC</OPTION>
<OPTION value="2 ">Salle de réunion n°2 - RDC</OPTION>
<OPTION value="Boston">Boston - RDC</OPTION>
<OPTION value="Mexico">Mexico - RDC</OPTION>
<OPTION value="Ottawa">Ottawa - RDC</OPTION>
<OPTION value="Quito">Quito - RDC</OPTION>
<OPTION value="Londres">Londres - 1er étage</OPTION>
<OPTION value="Paris">Paris - 1er étage</OPTION>
<OPTION value="Prague">Prague - 1er étage</OPTION>
<OPTION value="Rome">Rome - 1er étage</OPTION>
</SELECT>
</td>
</tr>

<div id="1" style="display:none">					
<table border="1">
<tr>
<td><?php echo "Réservation de la salle n°1 au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>  
</div>
							
<div id="2" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle n°2 au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Boston" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Boston au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table> 
</div>
						
<div id="Mexico" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Mexico au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>  
</div>
						
<div id="Ottawa" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Ottawa au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Quito" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Quito au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Londre" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Londre au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>  
</div>
						
<div id="Paris" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Paris au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table> 
</div>
						
<div id="Prague" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Prague au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Rome" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Rome au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>


Merci de votre aide, qui pourrait m'être si précieuse
0
Bonjour,
Je vous remercie pour ce script, il marche à merveille!
Il va m'être très util!!

Un grand merci,
Igor.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Utilisateur anonyme
1 sept. 2008 à 18:52
salut
merci de m'avoir répondu aussi vite

j'ai remplacé le deuxieme name="type" par id="type" et var type = document.getElementById("type").value;
mais ca marche toujours pas je te remet le code pour que tu le réetudie si t'as le temps

script:
function changementType() 
{


var type = document.getElementById("type").value;


if (type == "Hebdomadaire") 
{
document.getElementById("hebdomadaire").style="display:block";
} 
else
{
document.getElementById("hebdomadaire").style="display:none";
}


if (type == "Mensuel")
{
document.getElementById("mensuel").style="display:block";
}
else
{
document.getElementById("mensuel").style="display:none";
}



if (type == "Quotidien")
{
document.getElementById("quotidien").style="display:block";
}
else
{
document.getElementById("quotidien").style="display:none";
}



}


formulaire

<label >Type:</label>
       <select name="type" id="type" onchange="changementType();">
       <option value="Hebdomadaire">Hebdomadaire</option>	   
	   <option value="Mensuel">Mensuel</option>	
	   <option value="Unique">Unique</option>	
	   <option value="Quotidien">Quotidien</option>		   		   
	   </select><br/>
	   
	   <div id ="hebdomadaire" style="display:none">
	   <select name="frequence" id="hebdomadaire_liste">
       <option value="Lundi">Lundi</option>	   
	   <option value="Mardi">Mardi</option>	
	   <option value="Mercredi">Mercredi</option>	
	   <option value="Jeudi">Jeudi</option>	
	   <option value="Vendredi">Vendredi</option>	
	   <option value="Samedi">Samedi</option>	
	   <option value="Dimanche">Dimanche</option>		   
	   </select>
	   </div>
	   
	   <div id="mensuel" style="display:none">
       <select name="frequence">
       <option value="1">1</option>	   
	   <option value="2">2</option>	
	   <option value="3">3</option>	
	   <option value="4">4</option>	
	   <option value="5">5</option>	
	   <option value="6">6</option>	
	   <option value="7">7</option>	
	   </select>fois par mois<br/>
	   </div>
	   
	  
	   <div id="quotidien" style="display:none">
	   <input type="checkbox" name="Lundi" />Lundi
	   <input type="checkbox" name="Mardi" />Mardi
	   <input type="checkbox" name="Mercredi" />Mercredi
	   <input type="checkbox" name="Jeudi" />Jeudi
	   <input type="checkbox" name="Vendredi" />Vendredi
	   <input type="checkbox" name="Samedi" />Samedi
	   <input type="checkbox" name="Dimanche" />Dimanche<br/>
	   
	   </div>
-1
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
1 sept. 2008 à 20:07
Comme ça chez moi ça marche sous firefox3:

<script language="javascript">
function changementType() {
	var type = document.getElementById("type").value;
	if (type == "Hebdomadaire") {
		document.getElementById("hebdomadaire").style.display="block";
	} else{
		document.getElementById("hebdomadaire").style.display="none";
	}
	if (type == "Mensuel"){
		document.getElementById("mensuel").style.display="block";
	}else{
		document.getElementById("mensuel").style.display="none";
	}
	if (type == "Quotidien"){
		document.getElementById("quotidien").style.display="block";
	}else{
		document.getElementById("quotidien").style.display="none";
	}
}
</script>
<label >Type:</label>
       <select name="type" id="type" onchange="changementType();">
       <option value="Hebdomadaire">Hebdomadaire</option>	   
	   <option value="Mensuel">Mensuel</option>	
	   <option value="Unique">Unique</option>	
	   <option value="Quotidien">Quotidien</option>		   		   
	   </select><br/>
	   
	   <div id ="hebdomadaire" style="display:none">
	   <select name="frequence" id="hebdomadaire_liste">
       <option value="Lundi">Lundi</option>	   
	   <option value="Mardi">Mardi</option>	
	   <option value="Mercredi">Mercredi</option>	
	   <option value="Jeudi">Jeudi</option>	
	   <option value="Vendredi">Vendredi</option>	
	   <option value="Samedi">Samedi</option>	
	   <option value="Dimanche">Dimanche</option>		   
	   </select>
	   </div>
	   
	   <div id="mensuel" style="display:none">
       <select name="frequence">
       <option value="1">1</option>	   
	   <option value="2">2</option>	
	   <option value="3">3</option>	
	   <option value="4">4</option>	
	   <option value="5">5</option>	
	   <option value="6">6</option>	
	   <option value="7">7</option>	
	   </select>fois par mois<br/>
	   </div>
	   
	  
	   <div id="quotidien" style="display:none">
	   <input type="checkbox" name="Lundi" />Lundi
	   <input type="checkbox" name="Mardi" />Mardi
	   <input type="checkbox" name="Mercredi" />Mercredi
	   <input type="checkbox" name="Jeudi" />Jeudi
	   <input type="checkbox" name="Vendredi" />Vendredi
	   <input type="checkbox" name="Samedi" />Samedi
	   <input type="checkbox" name="Dimanche" />Dimanche<br/>
	   
	   </div>
0
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
18 sept. 2010 à 20:00
quand tu appelles ta fonction liste_deroulante_prof(math);

il faut que tu lui passes une valeur sous forme de string (chaine)

hors pour php math n'est pas une chaine mais une constante

pour que ce soit une chaine il faut encadrer par des ' ou des"

donc:

liste_deroulante_prof('math');


idem pour tous les autres appels
-1
Utilisateur anonyme
1 sept. 2008 à 18:29
salut
merci a toi de m'avoir répondu (je suis vraiment nul en javascript) j'ai adapté ton script mais ca ne marche pas il n'y a rien qui s'affiche voila le code adapté

function changementType() 
{


var type = document.getElementById("type");


if (type == "Hebdomadaire") 
{
document.getElementById("hebdomadaire").style="display:block";
} 
else
{
document.getElementById("hebdomadaire").style="display:none";
}


if (type == "Mensuel")
{
document.getElementById("mensuel").style="display:block";
}
else
{
document.getElementById("mensuel").style="display:none";
}



if (type == "Quotidien")
{
document.getElementById("quotidien").style="display:block";
}
else
{
document.getElementById("quotidien").style="display:none";
}



}



et voila le formulaire


<label >Type:</label>
       <select name="type" name="type" onchange="changementType();">
       <option value="Hebdomadaire">Hebdomadaire</option>	   
	   <option value="Mensuel">Mensuel</option>	
	   <option value="Unique">Unique</option>	
	   <option value="Quotidien">Quotidien</option>		   		   
	   </select><br/>
	   
	   <div id ="hebdomadaire" style="display:none">
	   <select name="frequence" id="hebdomadaire_liste">
       <option value="Lundi">Lundi</option>	   
	   <option value="Mardi">Mardi</option>	
	   <option value="Mercredi">Mercredi</option>	
	   <option value="Jeudi">Jeudi</option>	
	   <option value="Vendredi">Vendredi</option>	
	   <option value="Samedi">Samedi</option>	
	   <option value="Dimanche">Dimanche</option>		   
	   </select>
	   </div>
	   
	   <div id="mensuel" style="display:none">
       <select name="frequence">
       <option value="1">1</option>	   
	   <option value="2">2</option>	
	   <option value="3">3</option>	
	   <option value="4">4</option>	
	   <option value="5">5</option>	
	   <option value="6">6</option>	
	   <option value="7">7</option>	
	   </select>fois par mois<br/>
	   </div>
	   
	  
	   <div id="quotidien" style="display:none">
	   <input type="checkbox" name="Lundi" />Lundi
	   <input type="checkbox" name="Mardi" />Mardi
	   <input type="checkbox" name="Mercredi" />Mercredi
	   <input type="checkbox" name="Jeudi" />Jeudi
	   <input type="checkbox" name="Vendredi" />Vendredi
	   <input type="checkbox" name="Samedi" />Samedi
	   <input type="checkbox" name="Dimanche" />Dimanche<br/>
	   
	   </div>


merci d'avance si tu me reréponds
-2
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
1 sept. 2008 à 18:37
Tu as des erreurs:

dans ta fonction:

var type = document.getElementById("type");

c'est:

var type = document.getElementById("type").value;


ensuite tu utilises l'accès par l'Id

dans <select name="type" name="type" onchange="changementType();">

il te faut l'id=

<select name="type" id="type" onchange="changementType();">


et verifies bien qu'ensuite tu ai bien le même id partout entre ta fonction et les <div
0
Dev24 Messages postés 1 Date d'inscription mardi 27 mai 2014 Statut Membre Dernière intervention 27 mai 2014
27 mai 2014 à 14:02
bonjour,
j'utilise ce script, il est bien fonctionne avec Firefox mais avec les autres navigateurs non....stp qui adapté ce script avec tous les navigateurs? ou une autre proposition fonctionne pour tous les navigateurs?
0
Utilisateur anonyme
1 sept. 2008 à 20:14
merci gaga et alain 42
ca marche super
merci encore
-2
Bonjour et merci pour ce scritp qui fonctionne nikel.
juste une question.
dans mon cas je l'utilise dans un form du compte client.
comment faire pour que l'orsque que le client revient sur cette page, la div soit ouverte par defaut sur le choix qu'avait enregistré le client.

Merci
-2
THEGUNNERKILLER
9 déc. 2008 à 16:19
Je sait pas je suis vraiment nul en javascript
DSL
bonne soirée
0
snaquekiller Messages postés 13 Date d'inscription mercredi 20 mai 2009 Statut Membre Dernière intervention 29 décembre 2009
3 juin 2009 à 20:11
bonjours bonjours jai suivit la conversation jai creer mon script mais il bug enfin jai des messages d'erreur :
<?php 
include('../conf.inc.php');	
// Connexion au serveur
mysql_connect("$db_host" , "$db_user", "$db_pass") or die("erreur de connexion au serveur $db_host . ");

// Selection de la table voulue
mysql_select_db($db_name) or die("erreur de connexion a la base de donnees");?>


<script language="javascript">
function changementType() {
	var type = document.getElementById("type").value;
	
	<?php 	
	$matiere_array = array ("math", "francais", "anglais", "espagnol", "histoire" , "ses" , "isi" , "physique_chimie" , "svt");
// Puis on fait une boucle pour tout afficher :
for ($numero = 0; $numero < 9; $numero++)
{
		echo "if (type == \"".$matiere_array[$numero]."\"){";
		echo "document.getElementById(\"".$matiere_array[$numero]."\").style.display=\"block\"";
		echo "} else{";
		echo "document.getElementById(\"".$matiere_array[$numero]."\").style.display=\"none\"";
		echo "}";
}
	?>

	if (type == "test"){
		document.getElementById("test").style.display="block";
	}else{
		document.getElementById("test").style.display="none";
	}
}
</script>


<label >Type:</label>
       <select name="type" id="type" onchange="changementType();">
		   <option value="math">Math</option>	   
		   <option value="francais">Francais</option>	
		   <option value="anglais">Anglais</option>	
		   <option value="espagnol">Espagnol</option>		
		   <option value="histoire">Histoire</option>		
		   <option value="ses">SES</option>		
		   <option value="isi">ISI</option>		
		   <option value="physique_chimie">Physique Chimie</option>			
		   <option value="svt">SVT</option>		   		   
		   <option value="test">test</option>		   		   
	   </select><br/>
	   
	   
	<?php  
function liste_deroulante_prof($matiere){
	echo  "<div id=\"". $matiere ."\" style=\"display:none\" >"
				."<select name=\"" . 'prof_' . $matiere ."\ id=\"".$matiere. '_liste'."\" >";		
		$selection_par_matiere = mysql_query(" SELECT * FROM prof WHERE matiere='$matiere' ");
	while($donnees = mysql_fetch_array($selection_par_matiere))
	{		
		echo "<option value=\"".$donnees['nom']."\">".$donnees['nom']."</option>";
	}
		echo "</select> </div>";
}

function test(){
	?>   <div id="test" style="display:none">
	   <select name="frequence" id="test_liste">
       <option value="Lundi">Lundi</option>	   
	   <option value="Mardi">Mardi</option>	
	   <option value="Mercredi">Mercredi</option>	
	   <option value="Jeudi">Jeudi</option>	
	   <option value="Vendredi">Vendredi</option>	
	   <option value="Samedi">Samedi</option>	
	   <option value="Dimanche">Dimanche</option>		   
	   </select>
	   </div>
<?php 
}
liste_deroulante_prof(math);
liste_deroulante_prof(francais);
liste_deroulante_prof(anglais);
liste_deroulante_prof(espagnol);
liste_deroulante_prof(histoire);
liste_deroulante_prof(svt);
liste_deroulante_prof(isi);
liste_deroulante_prof(ses);
liste_deroulante_prof(physique_chimie);
test();

/* 	if (type == "Hebdomadaire") {
		document.getElementById("hebdomadaire").style.display="block";
	} else{
		document.getElementById("hebdomadaire").style.display="none";
	}
	
	if (type == "Mensuel"){
		document.getElementById("mensuel").style.display="block";
	}else{
		document.getElementById("mensuel").style.display="none";
	}
} */mysql_close();?>

il me dit comme erreur :

Notice: Use of undefined constant math - assumed 'math' in www\site\Prof\admin.php on line 77

Notice: Use of undefined constant francais - assumed 'francais' in www\site\Prof\admin.php on line 78

Notice: Use of undefined constant anglais - assumed 'anglais' in www\site\Prof\admin.php on line 79

Notice: Use of undefined constant espagnol - assumed 'espagnol' in www\site\Prof\admin.php on line 80

Notice: Use of undefined constant histoire - assumed 'histoire' in www\site\Prof\admin.php on line 81

Notice: Use of undefined constant svt - assumed 'svt' in www\site\Prof\admin.php on line 82

Notice: Use of undefined constant isi - assumed 'isi' in www\site\Prof\admin.php on line 83

Notice: Use of undefined constant ses - assumed 'ses' in www\site\Prof\admin.php on line 84

Notice: Use of undefined constant physique_chimie - assumed 'physique_chimie' in www\site\Prof\admin.php on line 85


biensur jaccpte tout aide pour amélioré ou sécurisé mon script voila :)
-2
Alain_42 Messages postés 5361 Date d'inscription dimanche 3 février 2008 Statut Membre Dernière intervention 13 février 2017 894
3 juin 2009 à 20:20
indefinied constant veux dire que tu envoie une constante à la fonction, laors qu'elle atend une chaine une valeur

donc:

<?php 
}
liste_deroulante_prof('math');
liste_deroulante_prof('francais');
liste_deroulante_prof('anglais');
liste_deroulante_prof('espagnol');
liste_deroulante_prof('histoire');
liste_deroulante_prof('svt');
liste_deroulante_prof('isi');
liste_deroulante_prof('ses');
liste_deroulante_prof('physique_chimie');
test();
-2
snaquekiller Messages postés 13 Date d'inscription mercredi 20 mai 2009 Statut Membre Dernière intervention 29 décembre 2009
3 juin 2009 à 22:36
merci de ta réponse si rapide
-2
Bonjour tout le monde, je viens de lire cette conversation même si elle a l'air terminer depuis longtemps, voila j'ai le même problème que TheGunnerKiller selon le choix fait dans une select, la div doit differer, j'ai suivi toute vos remarque sur cette conversation, mais cela ne marche pas...quelqu'un pourrait-il m'aider a trouver mon erreur?
<script type="text/javascript">
function changementType() 
{

var type = document.getElementById("type").value;


if (type == "1") 
{
document.getElementById("1").style="display:block";
} 
else
{
document.getElementById("1").style="display:none";
}


if (type == "2")
{
document.getElementById("2").style="display:block";
}
else
{
document.getElementById("2").style="display:none";
}



if (type == "Boston")
{
document.getElementById("Boston").style="display:block";
}
else
{
document.getElementById("Boston").style="display:none";
}


if (type == "Mexico")
{
document.getElementById("Mexico").style="display:block";
}
else
{
document.getElementById("Mexico").style="display:none";
}


if (type == "Ottawa")
{
document.getElementById("Ottawa").style="display:block";
}
else
{
document.getElementById("Ottawa").style="display:none";
}


if (type == "Quito")
{
document.getElementById("Quito").style="display:block";
}
else
{
document.getElementById("Quito").style="display:none";
}


if (type == "Londre")
{
document.getElementById("Londre").style="display:block";
}
else
{
document.getElementById("Londre").style="display:none";
}


if (type == "Paris")
{
document.getElementById("Paris").style="display:block";
}
else
{
document.getElementById("Paris").style="display:none";
}


if (type == "Prague")
{
document.getElementById("Prague").style="display:block";
}
else
{
document.getElementById("Prague").style="display:none";
}


if (type == "Rome")
{
document.getElementById("Rome").style="display:block";
}
else
{
document.getElementById("Rome").style="display:none";
}


}
</script>

Ca c'est ma fonction javascript

<tr>
<td>Salle </td>
<td>
<SELECT name="type" id="type" onchange="changementType();">
<OPTION value="1">Salle de réunion n°1 - RDC</OPTION>
<OPTION value="2 ">Salle de réunion n°2 - RDC</OPTION>
<OPTION value="Boston">Boston - RDC</OPTION>
<OPTION value="Mexico">Mexico - RDC</OPTION>
<OPTION value="Ottawa">Ottawa - RDC</OPTION>
<OPTION value="Quito">Quito - RDC</OPTION>
<OPTION value="Londres">Londres - 1er étage</OPTION>
<OPTION value="Paris">Paris - 1er étage</OPTION>
<OPTION value="Prague">Prague - 1er étage</OPTION>
<OPTION value="Rome">Rome - 1er étage</OPTION>
</SELECT>
</td>
</tr>

<div id="1" style="display:none">					
<table border="1">
<tr>
<td><?php echo "Réservation de la salle n°1 au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>  
</div>
							
<div id="2" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle n°2 au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Boston" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Boston au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table> 
</div>
						
<div id="Mexico" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Mexico au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>  
</div>
						
<div id="Ottawa" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Ottawa au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Quito" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Quito au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Londre" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Londre au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>  
</div>
						
<div id="Paris" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Paris au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table> 
</div>
						
<div id="Prague" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Prague au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>
						
<div id="Rome" style="display:none">
<table border="1">
<tr>
<td><?php echo "Réservation de la salle Rome au $date";?></td>
</tr>
<tr>
<td>09h00 - 10h30<input type=radio name="horaire" value="9h00-10h30"></td>
</tr>
<tr>
<td>10h30 - 12h00<input type=radio name="horaire" value="10h30-12h00"></td>
</tr>
<tr>
<td>12h00 - 14h00<input type=radio name="horaire" value="12h00-14h00"></td>
</tr>
<tr>
<td>14h00 - 15h30<input type=radio name="horaire" value="14h00-15h30"></td>
</tr>
<tr>
<td>15h30 - 17h00<input type=radio name="horaire" value="15h30-17h00"></td>
</tr>
<tr>
<td>17h00 - 18h00<input type=radio name="horaire" value="17h00-18h00"></td>
</tr>
</table>
</div>


Merci de votre aide, qui pourrait m'être si précieuse
-2