Probleme avec IE et Opera

Résolu
cs_SuperChouquette Messages postés 37 Date d'inscription dimanche 24 février 2008 Statut Membre Dernière intervention 18 mai 2010 - 24 avril 2009 à 23:16
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 - 25 avril 2009 à 16:25
Bonjour, je suis débutant et je tente de faire un script qui permette d'effectuer une recherche dans une liste, celui- ci fonctionne parfaitement sous Mozilla Firefox et sous Safari mais il ne fonctionne pas correctement sous internet explorer et opéra, pourriez vous m'aider ? je ne sais pas du tout à quoi cela est du.

Vous pouvez tester le script à cet adresse :
http://www.chouquette.fr/PB-IE_OPERA.html

et voici le code source :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv= "Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function remplacer(letexteModif,motif)
{
    positionmotif = letexteModif.search(motif);
    if(positionmotif != -1)
    {
        partieAvantMotif = letexteModif.substring(0, positionmotif);
        positionmotif2 = positionmotif + motif.length;
        positionmotif3 = letexteModif.length;
        partieApresMotif =     letexteModif.substring(positionmotif2 , positionmotif3);
        retourSanMotif = partieAvantMotif + partieApresMotif;
    }
    else
    {
        retourSanMotif = letexteModif;
    }
        
return retourSanMotif;
}

function recherche()
{    if (document.getElementById('recherchechamp').value '' || document.getElementById('recherchechamp').value ' ')
    {
        i =0;
        while(document.getElementById('userNom_'+i).innerHTML != "555FINLISTEMEMBREINVITE555" && i < 5000)
        {
            var texte = document.getElementById('userNom_'+i).innerHTML;
            texte = texte.replace("", "");
            texte = texte.replace("", "");
             document.getElementById('userNom_'+i).innerHTML = texte;
            document.getElementById('userHTML_'+i).style.display='block';
            i++;
        }

    }
    else
    {
        i =0;
        while(document.getElementById('userNom_'+i).innerHTML != "555FINLISTEMEMBREINVITE555" && i < 5000)
        {
            texte = document.getElementById('userNom_'+i).innerHTML;
            texte = remplacer(texte,"");
            texte = remplacer(texte,"");
             document.getElementById('userNom_'+i).innerHTML = texte;
            document.getElementById('userHTML_'+i).style.display='block';
            
            textePetit = texte;
            textePetit = textePetit.toLowerCase();
            rechercheValue =  document.getElementById('recherchechamp').value;
            rechercheValue = rechercheValue.toLowerCase();
            position = textePetit.search(rechercheValue);
            
            
            if(position != -1)
            {
                partie1 = texte.substring(0, position);
                position2 = position + rechercheValue.length;
                partie2 = texte.substring(position,position2);
                position3 = texte.length;
                partie3 = texte.substring(position2,position3);
                
                texteFinal = partie1 + " " + partie2 + " " + partie3;
                                
                document.getElementById('userNom_'+i).innerHTML = texteFinal;
                texteFinal = '';
                position2 = 0;
                position3 = 0;
                document.getElementById('userHTML_'+i).style.display='block';
            }
            else
            {
                document.getElementById('userHTML_'+i).style.display='none';
            }
            position = 0;
            i++;
        }
    }
    return 0;
}
</script>
<title>test</title>
</head>

    

    
    

        Findus Findus
    

    

    
    

        Alligator
    

    

    
    

        Pasteque
    

    

    
    

        Ananas
    

    

    
    

        Concombre
    

    

    
    

        Danielle Evenou
    

    

555FINLISTEMEMBREINVITE555
    

</html>

Merci !

7 réponses

Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
25 avril 2009 à 10:48
Bonjour,
tu as la même erreur avec les autres navigateurs
la différence c'est qu'ils continuent malgré tout,
    IE et Opera s'arrêtent
tu testes ocument.getElementById('userNom_'+i).innerHTML !=
      "555FINLISTEMEMBREINVITE555" && i < 5000
or après
vient

    donc sur
    ben ça plante :!
tu aurais pu (du ?) trouver plus simple pour boucler !

pour pallier ( temporairement !?! ) avec d'utiliser
    document.getElementById('userNom_'+i).innerHTML
teste s'il existe : if ( document.getElementById('userNom_'+i) )...
Cordialement [mon Site] [M'écrire] Bul

au fait, ça aide un ch'tiot peu :
Navigateurs |Quelques Explications |----

Chrome, contrôler page actuelle / Options pour développeurs
/ Console Javascript, ----

FireFox, Outils / Console d'erreurs
et mieux : télécharger FireBug, ----

Internet
Explorer, activer le deboggage : Outils/options Internet/Avancés
dans la liste, sous "Navigation" : décocher
o Afficher une notification de chaque erreur de script
o Désactiver le débogage de Scripts (Internet Explorer)
et mieux (pour IE < 8) : télécharger le Debogger IE
voir aussi : DebugBar et Companion JS, ----

K-Meleon, utils / Cons, ----

Opera, utils / Asole d'erreurs, ----

Safari, Debug / Show JavaScript Console
° modifier Fichier com.apple.Safari.plist situé dans le
répertoire : Support:\Documents and Settings\utilisateur
\Application Data\Apple Computer\Safari\Preferences\
y ajouter <key>IncludeDebugMenu</key>
----
3
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
25 avril 2009 à 11:41
var i=0
while ( document.getElementById('userNom_'+i) )
{ traitements;
  i++;
}
doit suffire d'ailleurs ( sans avoir testé/regardé )
3
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
25 avril 2009 à 13:19
>>j'ai du rajouter texte = remplacer(texte,"");...
bah.... si tu utilises replace : chaîne.replace(/ce que tu veux/gi,"n'importe quoi");
g : pour toutes les occurrences
i : pour ne pas distinguer les majuscules des minuscules
@+
3
cs_SuperChouquette Messages postés 37 Date d'inscription dimanche 24 février 2008 Statut Membre Dernière intervention 18 mai 2010
25 avril 2009 à 13:00
Merci beacoup pour ta réponse ! ça m'a aidé et j'avais aussi une autre erreurJe ne sais pas pourquoi IE et Opéra créaient les en majuscule donc j'ai du rajouter texte <gras>remplacer(texte,""); et texte remplacer(texte,"</gras>"); pour enlever ces balise et que ca fonctionne.
0

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

Posez votre question
cs_SuperChouquette Messages postés 37 Date d'inscription dimanche 24 février 2008 Statut Membre Dernière intervention 18 mai 2010
25 avril 2009 à 13:06
Au final pour ceux que ca intéressent, voici mon code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv= "Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">

function remplacer(letexteModif,motif)
{
    positionmotif = letexteModif.indexOf(motif);
    if(positionmotif != -1)
    {
        partieAvantMotif = letexteModif.substring(0, positionmotif);
        positionmotif2 = positionmotif + motif.length;
        positionmotif3 = letexteModif.length;
        partieApresMotif =     letexteModif.substring(positionmotif2 , positionmotif3);
        retourSanMotif = partieAvantMotif + partieApresMotif;
    }
    else
    {
        retourSanMotif = letexteModif;
    }
       
return retourSanMotif;
}

function recherche()
{
    if (document.getElementById('recherchechamp').value '' || document.getElementById('recherchechamp').value ' ')
    {
        q =0;
        while(document.getElementById('userNom_'+q))
        {
            var texte = document.getElementById('userNom_'+q).innerHTML
            texte = texte.replace("", "");
            texte = texte.replace("", "");
            texte = remplacer(texte,"");
            texte = remplacer(texte,"");
             document.getElementById('userNom_'+q).innerHTML = texte;
            document.getElementById('userHTML_'+q).style.display='block';
            q++;
        }

    }
    else
    {
        z =0;
        while(document.getElementById('userNom_'+z))
        {
            texte = document.getElementById('userNom_'+z).innerHTML;
            texte = remplacer(texte,"");
            texte = remplacer(texte,"");
            texte = remplacer(texte,"");
            texte = remplacer(texte,"");
             document.getElementById('userNom_'+z).innerHTML = texte;
            document.getElementById('userHTML_'+z).style.display='block';
           
            textePetit = texte;
            textePetit = textePetit.toLowerCase();
            rechercheValue =  document.getElementById('recherchechamp').value;
            rechercheValue = rechercheValue.toLowerCase();
            position =  textePetit.indexOf(rechercheValue);
           
           
            if(position != -1)
            {
                partie1 = texte.substring(0, position);
                position2 = position + rechercheValue.length;
                partie2 = texte.substring(position,position2);
                position3 = texte.length;
                partie3 = texte.substring(position2,position3);
               
                texteFinal = partie1 + " " + partie2 + " " + partie3;
                               
                document.getElementById('userNom_'+z).innerHTML = texteFinal;
                texteFinal = '';
                position2 = 0;
                position3 = 0;
                document.getElementById('userHTML_'+z).style.display='block';
            }
            else
            {
                document.getElementById('userHTML_'+z).style.display='none';
            }
            position = 0;
            z++;
        }
    }
    return 0;
}
</script>
<title>test</title>
</head>

   

   
   

        Findus Findus
   

   

   
   

        Alligator
   

   

   
   

        Pasteque
   

   

   
   

        Ananas
   

   

   
   

        Concombre
   

   

   
   

        Danielle Evenou
   

   

</html>
0
cs_SuperChouquette Messages postés 37 Date d'inscription dimanche 24 février 2008 Statut Membre Dernière intervention 18 mai 2010
25 avril 2009 à 16:14
Merci beaucoup pour ton aide ! vous pouvez tester le code ici : http://www.chouquette.fr/Fichiers/formSearch.html
et sinon voici le code final :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">

function recherche()
{

    if (document.getElementById('recherchechamp').value == '')
    {
        supprContenu();
        q =0;
        while(document.getElementById('userNom_'+q))
        {
            var texte = document.getElementById('userNom_'+q).innerHTML
            texte = texte.replace(//gi,"");
            texte = texte.replace(/<\/strong>/gi,"");
             document.getElementById('userNom_'+q).innerHTML = texte;
            document.getElementById('userHTML_'+q).style.display='block';
            q++;
        }

    }
    else
    {
        texteEntrer();
        z =0;
        while(document.getElementById('userNom_'+z))
        {
            texte = document.getElementById('userNom_'+z).innerHTML;
            texte = texte.replace(//gi,"");
            texte = texte.replace(/<\/strong>/gi,"");
             document.getElementById('userNom_'+z).innerHTML = texte;
            document.getElementById('userHTML_'+z).style.display='block';
           
            textePetit = texte;
            textePetit = textePetit.toLowerCase();
            rechercheValue =  document.getElementById('recherchechamp').value;
            rechercheValue = rechercheValue.toLowerCase();
            position =  textePetit.indexOf(rechercheValue);
           
           
            if(position != -1)
            {
                partie1 = texte.substring(0, position);
                position2 = position + rechercheValue.length;
                partie2 = texte.substring(position,position2);
                position3 = texte.length;
                partie3 = texte.substring(position2,position3);
               
                texteFinal = partie1 + " " + partie2 + " " + partie3;
                               
                document.getElementById('userNom_'+z).innerHTML = texteFinal;
                texteFinal = '';
                position2 = 0;
                position3 = 0;
                document.getElementById('userHTML_'+z).style.display='block';
            }
            else
            {
                document.getElementById('userHTML_'+z).style.display='none';
            }
            position = 0;
            z++;
        }
    }
    return 0;
}

function texteEntrer()
{
    document.getElementById('croix').style.display='block';
    document.getElementById('recherchechamp').style.borderRight='none';
    document.getElementById('recherchechamp').style.width='176px';
}

function changerFond(idUser, etat)
{
    if(etat == true) {
        document.getElementById('userHTML_'+idUser).style.backgroundColor='#dce1e8';
    }
    else {
        document.getElementById('userHTML_'+idUser).style.backgroundColor='#ffffff';
    }
}

function supprContenu()
{
    document.getElementById('recherchechamp').value='';
    document.getElementById('croix').style.display='none';
    document.getElementById('recherchechamp').style.borderRight='1px solid #bdc7d8';
    document.getElementById('recherchechamp').style.width='192px';
}

function focusRecherche()
{
    document.getElementById('recherchechamp').value='';
    document.getElementById('recherchechamp').style.color='#000000';
}

function blurRecherche()
{
    document.getElementById('recherchechamp').value='Veuillez sair le nom d\'un ami';
    document.getElementById('recherchechamp').style.color='#777777';
}

function cocherDecocher(container_id,state)
 {
  var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
  for (var i=0;i<checkboxes.length;i++)
   {
    if(checkboxes[i].type == 'checkbox')
     {
      checkboxes[i].checked = state;
     }
   }
  return true;
 }
</script>
<style type="text/css">
* {
padding:0;
margin:0;
}

body {
    font-family:Arial, Helvetica, sans-serif;
    padding-top:200px;
    width:100%;
}

#listeAmis {
    clear:both;
    font-size:11px;
    height:114px;
    width:198px;
    border-top:1px solid #bdc7d8;
    border-right:1px solid #bdc7d8;
    border-left:1px solid #bdc7d8;
    border-bottom:2px solid #bdc7d8;
    overflow:auto;
}

#listeAmis strong, #listeAmis STRONG {
    background-color:#dce1e8;
    font-weight:bold;
}

#listeAmis label {
    vertical-align:middle;
    padding-bottom:7px;
    height:12x;
}

#listeAmis div {
    height:19px;
    vertical-align:middle;
}

.rechercheAmis {
    border-top:1px solid #bdc7d8;
    border-right:1px solid #bdc7d8;
    border-left:1px solid #bdc7d8;
    border-bottom:none;
    padding-top:3px;
    padding-left:3px;
    padding-right:3px;
    font-size:11px;
    width:192px;
    float:left;
    height:16px;
    color:#000000;
}

#croix {
    border-top:1px solid #bdc7d8;
    border-right:1px solid #bdc7d8;
    border-left:none;
    border-bottom:none;
    font-weight:bold;
    color:#b1bdd6;
    font-size:10px;
    float:left;
    width:11px;
    height:16px;
    padding-left:5px;
    cursor:pointer;
    padding-top:3px;
    display:none;
}

.bottomForm {
    font-size:11px;
    width:200px;
    text-align:center;
}

.bottomForm input[type=submit] {
    color: #f7f7f7;
    font-weight: normal;
    height:22px;
    font-size:11px;
    background: #3b5998;
    border-top: 1px solid #d9dfea;
    border-left: 1px solid #d9dfea;
    border-right: 1px solid #0e1f5b;
    border-bottom: 1px solid #0e1f5b;
    cursor: pointer;
    margin-top:2px;
    padding: 1px 3px;
}

.formAmis {
    margin-left:auto;
    margin-right:auto;
    width:200px;
}

</style>
<title>Recherche Liste</title>
</head>

<form action="amis.php" method="post" class="formAmis">

X

   

       
        <label id="userNom_0" for="user0">Marc</label>
       

   

   

       
        <label id="userNom_1" for="user1">Pierre</label>
       

   

   

       
        <label id="userNom_2" for="user2">Paul</label>
       

   

   

       
        <label id="userNom_3" for="user3">Marie</label>
       

   

   

       
        <label id="userNom_4" for="user4">Jean</label>
       

   

   

       
        <label id="userNom_5" for="user5">Anne</label>
       

   

   

       
        <label id="userNom_6" for="user6">Charles</label>
       

   

   

       
        <label id="userNom_7" for="user7">Ines</label>
       

   

    [# Tout cocher] - [# Tout décocher]
   

   

</form>

</html>
0
Bul3 Messages postés 4933 Date d'inscription samedi 1 juillet 2006 Statut Membre Dernière intervention 2 février 2015 16
25 avril 2009 à 16:25
nickel si ça baigne...
en général ( mais je sais que généralement il est stupide de généraliser )
on fait cela avec un select.
"adaptation" intéressante, mon foie.
@+
0
Rejoignez-nous