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 :

Afficher / cacher un div => Exécuter une action


Sujet :

JavaScript

  1. #1
    Expert confirmé
    Avatar de pc75
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    3 662
    Détails du profil
    Informations personnelles :
    Âge : 69
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2004
    Messages : 3 662
    Points : 4 047
    Points
    4 047
    Par défaut Afficher / cacher un div => Exécuter une action
    Bonjour,

    Je n'ai pas trouvé de solution à mon souci dans le forum (j'ai peut-être mal cherché).

    Voila un extrait de mon code :

    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
     
    <html>
    <head>
    <script type="text/javascript">
    function Creer()
    	{
    	document.getElementById("Loupe").style.visibility = "visible";
    	}
     
    function Chercher()
    	{
    	alert("OK");
    	}
    </script>
     
    </head>
    <body background="images/bg.gif">
    .....
    <div style="cursor:pointer;" id="Loupe" style="visibility:hidden">
    <img SRC="../images/Loupe.gif" onclick="javascript:Chercher();">
    </div>
    .....
    <a href="#" onclick="Creer()">
    <img SRC="../images/creer.gif">
    </a>
    Quand je clique sur l'image "creer.gif", la fonction Creer() rend visible le div et par conséquent l'image 'loupe.gif".

    Par contre, quand je clique ensuite sur cette image, j'ai une erreur javascript et la fonction Chercher() ne s'exécute pas.
    (Cet objet ne gère pas cette propriété ou cette méthode)

    Qualqu'un voit ce que j'ai raté ?

  2. #2
    Expert éminent sénior

    Avatar de vermine
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    6 582
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2008
    Messages : 6 582
    Points : 79 912
    Points
    79 912
    Par défaut
    Bonjour,

    En copiant tel quel ce code, j'obtiens l'alert "OK" sur IE7.

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Un peu plus propre :

    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
    <html>
    <head>
        <title>test</title>
        <script type="text/javascript">
        function Creer()
        {
            document.getElementById("Loupe").style.visibility = "visible";
        }
     
        function Chercher()
        {
            alert("OK");
        }
        </script>
     
    </head>
    <body>
        <div style="cursor:pointer;visibility:hidden" id="Loupe" >
            <img SRC="../images/Loupe.gif" onclick="Chercher();">
        </div>
        <a href="#" onclick="Creer()">
            <img SRC="../images/creer.gif">
        </a>
     
    </body>
    </html>
    A+

  4. #4
    Expert confirmé
    Avatar de pc75
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    3 662
    Détails du profil
    Informations personnelles :
    Âge : 69
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2004
    Messages : 3 662
    Points : 4 047
    Points
    4 047
    Par défaut
    Re,

    Merci de t'intéresser à mon problème.

    Je viens de tester sous FF et tout fonctionne.

    Par contre sous IE6, ça plante.

    Le continue de chercher aussi de mon côté.

  5. #5
    Invité
    Invité(e)
    Par défaut
    Re,

    Cela fonctionne bien sous IE6, enfin chez moi

    A+

  6. #6
    Expert confirmé
    Avatar de pc75
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    3 662
    Détails du profil
    Informations personnelles :
    Âge : 69
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2004
    Messages : 3 662
    Points : 4 047
    Points
    4 047
    Par défaut
    Re,

    J'ai simplifié mon code au maximum, mais même en cliquant sur l'image à côté du titre "Dossier", ça plante.

    Le code complet :
    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
     
    <html>
    <head>
     
    <script type="text/javascript">
    function Creer()
    	{
    	document.getElementById("Chercher").style.display = "none";
    	document.getElementById('Loupe').style.visibility = 'visible';
    	}
     
    function Chercher()
    	{
    	alert("OK");
    	}
    </script>
     
    </head>
    <body background="images/bg.gif">
    <br>
    <p align="center">
    	<font face="arial" size="4" color="Firebrick">
    	<strong>
    	Rechercher un dossier
    	</strong>
    	</font>
     
     
    <form name="frmRecherche" method="post">
    	<input type="hidden" name="txtAction">
     
    	<table align="center" border="4" width="85%" bgcolor="LightGrey">
    		<tr>
    			<td>
    				<font face="arial" size="4" color="SteelBlue">
    				N° : 
    				<input type="text" name="txtNumero" value="" size="10" maxlength="8">
    				</font>
    			</td>
    			<td>
    				<font face="arial" size="4" color="SteelBlue">
    				Nom : 
    				<input type="text" name="txtNom" value="" size="10" maxlength="255">
    				</font>
    			</td>
    			<td>
    				<font face="arial" size="4" color="SteelBlue">
    				Prénom : 
    				<input type="text" name="txtPrenom" value="" size="10" maxlength="50">
    				</font>
    			</td>
    			<td>
    				<font face="arial" size="4" color="SteelBlue">
    				Dossier : 
    				<input type="text" name="txtDossier" value="" size="10" maxlength="10">
    				</font>
    				<span>
    					<img SRC="../images/Loupe.gif" id="Loupe" onclick="Chercher()">
    				</span>
    			</td>
    		</tr>
    		<tr>
    			<td colspan="4" align="center">
    				<input type="submit" id="Chercher" value="Lancer la recherche">
    			</td>
    		</tr>
    	</table>
    	<p align="center">
    		<a href="#" onclick="Creer()">
    		<img SRC="../images/creer.gif" border="0" alt="Créer un nouveau dossier" title="Créer un nouveau dossier" WIDTH="100" HEIGHT="25">
    		</a>
    	</p>
     
    </form>
    </body>
    </html>

  7. #7
    Expert confirmé
    Avatar de pc75
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    3 662
    Détails du profil
    Informations personnelles :
    Âge : 69
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2004
    Messages : 3 662
    Points : 4 047
    Points
    4 047
    Par défaut
    Re,

    C'est bon, j'ai trouvé.

    L'id du bouton "Lancer la recherche" était Chercher et j'avais une fonction javascript qui portait le même nom.

    J'ai changé l'id du bouton et ça fonctionne.

    Merci.

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

Discussions similaires

  1. Exécuter une action à une heure précise
    Par Rhadamanthe59 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 09/02/2006, 23h12
  2. Exécuter une action quand on ferme le navigateur
    Par Leobaillard dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 08/01/2006, 12h41
  3. Réponses: 1
    Dernier message: 25/10/2005, 13h25
  4. Exécuter une action à la fermeture d'une fenêtre
    Par wwave dans le forum Servlets/JSP
    Réponses: 12
    Dernier message: 28/07/2005, 15h15
  5. Afficher, cacher plusieurs divs
    Par Buku dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 18/03/2005, 10h28

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