IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

getElementById


Sujet :

JavaScript

  1. #1
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Novembre 2003
    Messages
    90
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 90
    Points : 83
    Points
    83
    Par défaut getElementById
    Salut, j'ai un problème avec mon code, il fonctionne très bien sous internet exploreur mais pas sous netscape et firefox. Lorsque j'utilise "l'attribut" ID, les tableaux sont affichés n'importe comment, cependant lorsque je retire cet "attribut", tout va bien mais alors mon javascript ne peux plus oppérer.
    voici le code:

    mes tableaux imbriqués:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    <table bordercolor="#EA1D24" cellspacing="0" cellpadding="2" border="1" style="margin-top:10px;margin-bottom:10px; " bgcolor="#FFFFFF" width="80%">
     
    echo "<tr class='ECLElementListe' id=\"liste".$i."\" >";
    	//echo "<tr class='ECLElementListe'>";//debug problème id!!!!
    		echo "<td onmouseover=\"TableMouseOver(this,$i);\" onmouseout=\"TableMouseOut(this,$i);\">";
     
    		echo "<table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'>";
    			echo "<tr onClick=\"document.location='".$href."'\">";
    				echo "<td>".$text."</td>";
    				echo "<td width='100px' align='left' id='CliquezIci".$i."' style='visibility:hidden'>cliquez ici</td>";
    			echo "</tr>";
    		echo "</table>";
    		echo "</td>";
    	echo "</tr>";
    Mon javascript qui affiche ou cache certainne ligne du tableau précédant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    while(document.getElementById('liste'+j))
    			{
    			if((j>=min)&&(j<=max))
    				{
    				document.getElementById('liste'+j).style.display='block';
    				nbPanel++;
    				}
    			else
    				{
    				document.getElementById('liste'+j).style.display='none';
    				}
    			j++;
    			}
    Si je remplace la ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo "<tr class='ECLElementListe' id=\"liste".$i."\" >";
    par la ligne d'en dessous qui est commenté ça marche mais plus d'ID!!!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
       //echo "<tr class='ECLElementListe'>";//debug problème id!!!!
    Quelqu'un aurait une idée?

  2. #2
    Expert éminent

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Points : 7 641
    Points
    7 641
    Par défaut Re: getElementById
    Citation Envoyé par Cyrilh7
    Quelqu'un aurait une idée?
    On peut voir le code HTML généré pour ce tableau?

    A mon avis, c'est un problème de cet ordre....

  3. #3
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Novembre 2003
    Messages
    90
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 90
    Points : 83
    Points
    83
    Par défaut
    Voila toute la page que lit Firefox:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    	<head>
      	<title>Point Service Randonn&eacute;e</title>
      	<link type="text/css" href="style1.css" rel="stylesheet" />
    	<script type="text/javascript">
    function ClignoteDrapeau()
    	{
     
    	var i=0;
    	while(document.getElementById('Drapeau'+i))
    			{
     
    			if(document.getElementById('Drapeau'+i).style.display=='none')
    				{
    				document.getElementById('Drapeau'+i).style.display='block';
    				}
    			else
    				{
    				document.getElementById('Drapeau'+i).style.display='none';
    				}
     
    			i++;
    			}
    	setTimeout("ClignoteDrapeau()", 500);	
    	}
     
    function TableMouseOver(obj,nb)
    		{
    		if(nb!=-1)
    			{
    			obj.bgColor='#E6E6E8';
    			document.getElementById('Drapeau'+nb).style.visibility='visible';
    			document.getElementById('CliquezIci'+nb).style.visibility='visible';
    			}
    		else
    			{
    			obj.bgColor='#E6E6E8';
    			}
    		} 
    function TableMouseOut(obj,nb)
    		{
    		if(nb!=-1)
    			{
    			obj.bgColor='#FFFFFF';
    			document.getElementById('Drapeau'+nb).style.visibility='hidden';
    			document.getElementById('CliquezIci'+nb).style.visibility='hidden';
    			}
    		else
    			{
    			obj.bgColor='#FFFFFF';
    			}
    		} 
    </script>
     
    	<script type="text/javascript">
    	function largeur_fenetre()	
    		{
     		if (window.innerWidth) return window.innerWidth;
     		else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
     		else return 0;
    		}
    	function hauteur_fenetre()
    		{
     		if (window.innerHeight) return window.innerHeight;
     		else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
    		//else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
     		else return 0;
    		}
    	function reconstruction()
    		{
     		if (largeur != largeur_fenetre() || hauteur != hauteur_fenetre())
     		window.history.go(0);
    		}
    	function set_largeur_carte()  
    		{	
    		set_carte();
    		set_drapeaux();
    		}
    	function set_carte()
    		{
    		document.getElementById('carte').height=hauteur;
    		document.getElementById('selCarte').height=hauteur;
    		var carteWidth=document.getElementById('carte').width;
    		document.getElementById('selCarte').width=carteWidth;
    		}
    	function set_drapeaux()
    		{
    		//Calcul du coefficient de réduction---
    		var hauteurDOrigine=document.getElementById('carteNatural').height;
    		var hauteurVisu=document.getElementById('carte').height;
    		var echelle=hauteurVisu/hauteurDOrigine;
     
    		var i=0;
    		while(document.getElementById('positionDrapeau'+i))
    			{
    			//Calcul la position des drapeaux
    			var x=parseInt(document.getElementById('positionDrapeauNaturel'+i).style.pixelLeft*echelle);
    			var y=parseInt(document.getElementById('positionDrapeauNaturel'+i).style.pixelTop*echelle);
    			document.getElementById('positionDrapeau'+i).style.pixelLeft=x;
    			document.getElementById('positionDrapeau'+i).style.pixelTop=y;
    			//Calcul la taille des drapeaux
    			var DWith=parseInt(document.getElementById('DrapeauNaturel'+i).width*echelle);
    			var DHeight=parseInt(document.getElementById('DrapeauNaturel'+i).height*echelle);
    			document.getElementById('Drapeau'+i).width=DWith;
    			document.getElementById('Drapeau'+i).height=DHeight;
    			i++;
    			}
    		}	
    	//initialiser la surveillance de Netscape
    	if(!window.largeur && window.innerWidth)
      		{
       		window.onresize = reconstruction;
       		largeur = largeur_fenetre();
       		hauteur = hauteur_fenetre();
      		}
    </script>
     
       </head>
     
      	<body id="page"  onLoad="setTimeout('ClignoteDrapeau()', 500)">
     
    	<script type="text/javascript">
    	document.body.style.overflow='hidden'; //permet de cacher les scrollbars d'internet exploreur
     	//initialiser la surveillance par l'Explorer Internet MS
     	if(!window.largeur && document.body && document.body.offsetWidth)
      		{
       		window.onresize = reconstruction;
       		largeur = largeur_fenetre();
      		hauteur = hauteur_fenetre();
      		}
    	</script>
     
    <table width="100%" height="100%" cellpadding="0"  cellspacing="0" border="0">  
          <tr>
        		<!-- début partie gauche -->      
          	<td valign="top">
     
    <div align="center">
    <table bordercolor="#EA1D24" cellspacing="0" cellpadding="2" border="1" style="margin-top:10px;margin-bottom:10px; " bgcolor="#FFFFFF" width="80%">
    <tr class='ECLElementListe' id="liste0" ><td onmouseover="TableMouseOver(this,0);" onmouseout="TableMouseOut(this,0);"><table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'><tr onClick="document.location='main.php?action=set-fiche&ID_Fiche=181'"><td>&nbsp;1 - la vallée du Lavedan d'Aulon</td><td width='100px' align='left' id='CliquezIci0' style='visibility:hidden'>cliquez ici</td></tr></table></td></tr><tr class='ECLElementListe' id="liste1" ><td onmouseover="TableMouseOver(this,1);" onmouseout="TableMouseOut(this,1);"><table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'><tr onClick="document.location='main.php?action=set-fiche&ID_Fiche=300'"><td>&nbsp;2 - le Pic du Jer et son funiculaire</td><td width='100px' align='left' id='CliquezIci1' style='visibility:hidden'>cliquez ici</td></tr></table></td></tr><tr class='ECLElementListe' id="liste2" ><td onmouseover="TableMouseOver(this,2);" onmouseout="TableMouseOut(this,2);"><table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'><tr onClick="document.location='main.php?action=set-fiche&ID_Fiche=391'"><td>&nbsp;3 - petite rando</td><td width='100px' align='left' id='CliquezIci2' style='visibility:hidden'>cliquez ici</td></tr></table></td></tr><tr id="listeVide0"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide1"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide2"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide3"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide4"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide5"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide6"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide7"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide8"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide9"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide10"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide11"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide12"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide13"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><tr id="listeVide14"><td onmouseover="TableMouseOver(this,-1);" onmouseout="TableMouseOut(this,-1);" >&nbsp;</td></tr><script type="text/javascript">nombreDeFiche=3; nbParPage=15;</script></table>
     
    <table width="80%">
    <tr><td><img  id="BtRetour" src='logos/debutDeLaListe.gif' border='0' onClick="pagePrecedante(); " align="left"><img id="BtSuite" src='logos/suiteDeLaListe.gif' border='0' onClick="pageSuivante();" align="right"></tr></td>
    </table>
    </div>
     
    <div class='BtRetour'><a href='main.php?action=afficher-choix'><img src='logos/retour3.gif' border='0'></a></div>
     
     
    <script type="text/javascript">
    function afficherPage()
    {
    var nbParPage=15;
    nombreDePage=nombreDeFiche/nbParPage;
    var min=(pageIndex-1)*nbParPage;
    var max=(pageIndex)*nbParPage-1;
    //Affichage de la liste-------------
    var j=0;
    var nbPanel=0;
    while(document.getElementById('liste'+j))
    			{
    			if((j>=min)&&(j<=max))
    				{
    				document.getElementById('liste'+j).style.display='block';
    				nbPanel++;
    				}
    			else
    				{
    				document.getElementById('liste'+j).style.display='none';
    				}
    			j++;
    			}		
    //complette la liste si nécessaire---------
     
    var k=0;
    while(document.getElementById('listeVide'+k))
    			{
    			//document.getElementById('listeVide'+k).style.display='none';
    			//document.write("ici");
    			if(nbPanel<nbParPage)
    				{
    				document.getElementById('listeVide'+k).style.display='block';
    				nbPanel++;
    				}
    			else
    				{
    				document.getElementById('listeVide'+k).style.display='none';
    				}	
    			k++;
    			}				
    //Affichage bt retour-----------
    if(pageIndex-1>=1)
    	{
    	//Cacher bouton retour
    	document.getElementById('BtRetour').style.visibility='visible';
    	}
    else
    	{
    	//Montrer bouton retour
    	document.getElementById('BtRetour').style.visibility='hidden';
    	}
     
    //Affichage bt suite------------
    if(pageIndex<nombreDePage)
    	{
    	//Cacher bouton suite
    	document.getElementById('BtSuite').style.visibility='visible';
    	}
    else
    	{
    	//Montrer bouton suite
    	document.getElementById('BtSuite').style.visibility='hidden';
    	}
    }
     
    function pagePrecedante()
    {
    if(pageIndex-1>=1)
    	{
    	pageIndex--;
    	afficherPage();
    	}
    }
     
    function pageSuivante()
    {
    if(pageIndex<nombreDePage)
    	{
    	pageIndex++;
    	afficherPage();
    	}
    }
     
     
    var pageIndex=1;
    afficherPage();
    </script>
     
     
     
    </td>
    		<td width=1 bgcolor="#A5A59D"></td>
     
        		<!-- fin partie gauche -->
        		<!-- début partie droite -->                        
          	<td  id="selCarte"><div style='overflow: hidden; visibility: hidden; DISPLAY: block; POSITION: absolute; z-index: 100; height:0px; width:0px;'><img id='carteNatural' src='../PSR/CarteAutomate/81.bmp'></div><div style='DISPLAY: block; POSITION: relative; z-index: 0;'><img id='carte' src='../PSR/CarteAutomate/81.bmp' ><div  id='positionDrapeauNaturel0'; style='overflow: hidden; visibility: hidden; DISPLAY: block; POSITION: absolute; z-index: 100; height:0px; width:0px; left:239px; top:386px;'><img id='DrapeauNaturel0'; src='logos/Drapeau.gif'></div><div NAME='drapeau'; id='positionDrapeau0'; style='DISPLAY: block; POSITION: absolute; left:239px; top:386px; z-index: 10;'><img id='Drapeau0'; src='logos/Drapeau.gif'  style='visibility: hidden;'></div><div  id='positionDrapeauNaturel1'; style='overflow: hidden; visibility: hidden; DISPLAY: block; POSITION: absolute; z-index: 100; height:0px; width:0px; left:131px; top:293px;'><img id='DrapeauNaturel1'; src='logos/Drapeau.gif'></div><div NAME='drapeau'; id='positionDrapeau1'; style='DISPLAY: block; POSITION: absolute; left:131px; top:293px; z-index: 10;'><img id='Drapeau1'; src='logos/Drapeau.gif'  style='visibility: hidden;'></div><div  id='positionDrapeauNaturel2'; style='overflow: hidden; visibility: hidden; DISPLAY: block; POSITION: absolute; z-index: 100; height:0px; width:0px; left:72px; top:83px;'><img id='DrapeauNaturel2'; src='logos/Drapeau.gif'></div><div NAME='drapeau'; id='positionDrapeau2'; style='DISPLAY: block; POSITION: absolute; left:72px; top:83px; z-index: 10;'><img id='Drapeau2'; src='logos/Drapeau.gif'  style='visibility: hidden;'></div></div></td>
        		<!-- fin partie droite -->        
          </tr>
    </table>
     
    <script type="text/javascript">
    set_largeur_carte();
    // document.write("largeur: "+largeur +" hauteur: "+hauteur);
    </script>
     
      	</body>
    </html>

  4. #4
    Membre confirmé
    Homme Profil pro
    Ingénieur réseau et sécurité / Consultant
    Inscrit en
    Août 2005
    Messages
    1 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Suisse

    Informations professionnelles :
    Activité : Ingénieur réseau et sécurité / Consultant
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2005
    Messages : 1 068
    Points : 493
    Points
    493
    Par défaut
    faut etre motivé....
    Il y a 10 types de personnes sur la planète. Ceux qui comprennent le binaire et ceux qui ne le comprennent pas...

  5. #5
    Expert éminent

    Avatar de denisC
    Profil pro
    Développeur Java
    Inscrit en
    Février 2005
    Messages
    4 050
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Service public

    Informations forums :
    Inscription : Février 2005
    Messages : 4 050
    Points : 7 641
    Points
    7 641
    Par défaut Re: getElementById
    Citation Envoyé par Cyrilh7
    document.getElementById('liste'+j).style.display='block';
    L'erreur était dans le premier post, désolé de t'avoir fait poster tout ça.

    Une ligne de tableau, c'est pas un block..... plutot un table-row. Dans le doute, ne mets rien ('').

  6. #6
    Membre régulier
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Novembre 2003
    Messages
    90
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 90
    Points : 83
    Points
    83
    Par défaut
    merci pour ton aide effectivement c'était ça!!

    PS: Désolé pour ceux que le code a impressionné (il est généré par un programme PHP) mais je ne savais pas quel autre partie du code pouvait être nécessaire?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. This.value au lieu de document.getElementById('field').value
    Par yoyot dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 04/03/2005, 14h02
  2. getElementById et Firefox
    Par ludo65 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 28/02/2005, 10h56
  3. getelementbyid innerhtml sur Opera?
    Par cynthia dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 31/12/2004, 10h44
  4. getElementsByName ou getElementById
    Par lepierre dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 21/10/2004, 15h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo