Pb Compatibilité d'un script sous FireFox

Kommius Messages postés 3 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 7 septembre 2009 - 4 déc. 2005 à 23:02
cs_bultez Messages postés 13615 Date d'inscription jeudi 13 février 2003 Statut Membre Dernière intervention 15 octobre 2013 - 5 déc. 2005 à 08:30
Salut à tous! Voilà, je cours à votre aide car j'ai trouvé un petit script sympa sur le site (22007 http://www.javascriptfr.com/code.aspx?ID=22007)

Le Code en question :

<OL>
<LI><html>
<LI><head>
<LI><title>
test
</title>
<LI><script language =<VAR>"JavaScript"</VAR>>
<LI>
function
afficherAutre() {
<LI>
var
a =
document
.
getElementById
(<VAR>"autre"</VAR>);
<LI>
var
m =
document
.
getElementById
(<VAR>"mots"</VAR>);
<LI>
<LI>
if
(
document
.form1.liste.value == 3)
<LI> {
<LI>
if
(a.style.display == <VAR>"none"</VAR>)
<LI> a.style.display = <VAR>"block"</VAR>;
<LI>
<LI>
if
(m.style.display == <VAR>"none"</VAR>)
<LI> m.style.display = <VAR>"block"</VAR>;
<LI> }
<LI>
else

<LI> {
<LI> a.style.display = <VAR>"none"</VAR>;
<LI> m.style.display = <VAR>"none"</VAR>;
<LI> }
<LI>}
<LI></script>
<LI></head>
<LI>
<LI>
<LI><form name=<VAR>"form1"</VAR> method=<VAR>"post"</VAR> action=<VAR>""</VAR>>
<LI>Choisissez une option :
<LI> <
select
name=<VAR>"liste"</VAR>
onChange
=<VAR>"afficherAutre()"</VAR>>
<LI> <option value=1>option1</option>
<LI> <option value=2>option2</option>
<LI> <option value=3>Autre</option>
<LI> </
select
>
<LI>


<LI> "display: none"</VAR>> Autre :
<LI> "text"</VAR> id=<VAR>"mots"</VAR> name=<VAR>"mots"</VAR> style=<VAR>"display: none"</VAR>>
<LI></form>
<LI>
<LI></html> </LI></OL>
Petit problème, il ne marche que sous IE complètement, mais j'aimerais le faire fonctionner sous FireFox.. Il me semble que j'avais lu quelquepart que c'est du à la fonction document.
getElementById... 

1 réponse

cs_bultez Messages postés 13615 Date d'inscription jeudi 13 février 2003 Statut Membre Dernière intervention 15 octobre 2013 30
5 déc. 2005 à 08:30
Bonjour,
je pense qu'à chaque fois que c'est possible,
il vaut mieux utiliser this. ch'tit exemple :

<html>
<head>
<title>test</title>
<script type="Text/JavaScript">
function afficherAutre(lst) {
var a = document.getElementById("autre");
var m = document.getElementById("mots");
if (lst.value == 3)
{
a.style.display = "block";
m.style.display = "block";
}
else
{
a.style.display = "none";
m.style.display = "none";
}
}
</script>
</head>

<form name="form1" method="post" action="">
Choisissez une option :
<select name="liste" onChange="afficherAutre(this);">
<option value=1>option1</option>
<option value=2>option2</option>
<option value=3>Autre</option>
</select>



Autre :

</form>

</html>

Cordialement. Bul. ~ Site ~
0
Rejoignez-nous