Script JavaScript pour formulaire - Page 2
Résolu
Précédent
- 1
- 2
Voici la solution:
/********Fichier appelé solution3.html (que tu peux copier-coller)******/
<html>
<head>
<script language='javascript'>
function afficher(selectedIndex)
{
ob=document.getElementById('co');
valeur=document.form.genre.options[selectedIndex].value;
if(valeur!="other")
{ob.innerHTML="";}
else{
ob.innerHTML="Précisez : <input type='text' name='genre_other'>";
}
}
</script>
</head>
<body>
<form name='form'>
Quel est le genre du groupe :
<select name="genre" onChange='afficher(selectedIndex);'>
<option value="HR">Hard Rock</option>
<option value="punk">Punk</option>
<option value="GM">Gothic Metal</option>
<option value="DM">Death Metal</option><
option value="BM">Black Metal</option>
<option value="TM">Trash Metal</option>
<option value="HM">Heavy Metal</option>
<option value="other">Autre</option>
</select>
<br>
<br>
</form>
<br>
<span id='co'></span>
</body>
</html>
/********Fichier appelé solution3.html (que tu peux copier-coller)******/
<html>
<head>
<script language='javascript'>
function afficher(selectedIndex)
{
ob=document.getElementById('co');
valeur=document.form.genre.options[selectedIndex].value;
if(valeur!="other")
{ob.innerHTML="";}
else{
ob.innerHTML="Précisez : <input type='text' name='genre_other'>";
}
}
</script>
</head>
<body>
<form name='form'>
Quel est le genre du groupe :
<select name="genre" onChange='afficher(selectedIndex);'>
<option value="HR">Hard Rock</option>
<option value="punk">Punk</option>
<option value="GM">Gothic Metal</option>
<option value="DM">Death Metal</option><
option value="BM">Black Metal</option>
<option value="TM">Trash Metal</option>
<option value="HM">Heavy Metal</option>
<option value="other">Autre</option>
</select>
<br>
<br>
</form>
<br>
<span id='co'></span>
</body>
</html>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Précédent
- 1
- 2