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 :

Delete Ok sur IE mais pas FF


Sujet :

JavaScript

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Février 2007
    Messages
    252
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 252
    Points : 85
    Points
    85
    Par défaut Delete Ok sur IE mais pas FF
    Bonjour a tous,

    J' ai un code de creation dynamique de lignes en JS. sur chaque ligne, j' ai un bouton Delete qui me permet de la supprimer.

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <script language="javascript">
     var bUniqueRowID = 0;
    function getXhr(){
        var xhr = null; 
    	if(window.XMLHttpRequest) // Firefox and others
    		xhr = new XMLHttpRequest(); 
    	else if(window.ActiveXObject){ // Internet Explorer 
    	   try {
    			xhr = new ActiveXObject("Msxml2.XMLHTTP");
    			} catch (e) {
    				xhr = new ActiveXObject("Microsoft.XMLHTTP");
    			}
    	}
    	else { // XMLHttpRequest not supported by your browser
    		alert(" Your browser does not support XMLHTTPRequest objects..."); 
    		xhr = false; 
    		} 
         return xhr
    	}
     
    	/**
    	*  method called when the user clicks on the button
    	*/
     
    function gobr(){
    	var xhr = getXhr()
    	// We defined what we gonna do with the response
    	xhr.onreadystatechange = function(){
    	// We do somthing once the server's response is OK
    	if(xhr.readyState == 4 && xhr.status == 200){
     
    			// Retrieve <table> ID and create a <tbody> element
     
    			var tbl = document.getElementById("brtable");
    			var tblBody = document.createElement("tbody");
    			var row = document.createElement("tr");
     
    			bUniqueRowID += 1;
     
    			var cell_1 = document.createElement("td");
    			cell_1.align="center";
    			cell_1.valign="center";
    			var cell_2 = document.createElement("td");
    			cell_2.align="center";
    			cell_2.valign="center";
    			var cell_3 = document.createElement("td");
    			cell_3.align="center";
    			cell_3.valign="center";
     
     
    		// Create the first cell which is a select
     
    			var cell1 = document.createElement("div");
    			cell1.innerHTML=xhr.responseText;
    			cell_1.appendChild(cell1);		
     
    		//Create the second cell a checked box
    			var cell2=document.createElement("input");
    			cell2.type="checkbox";
    			cell2.name="brdedicated";
    			cell_2.appendChild(cell2);
     
    		// Create the third cell which is a button
    			var cell3=document.createElement("input");
    			cell3.type="button";
    			cell3.value="Delete"
    			cell3.onclick=delRowbr;
    			cell_3.appendChild(cell3);						
     
    			// add cells to the row
    			row.appendChild(cell_1);
    			row.appendChild(cell_2);
    			row.appendChild(cell_3);
     
    		// add the row to the end of the table body
    			tblBody.appendChild(row);
     
    		// put the <tbody> in the <table>
    			tbl.appendChild(tblBody);
     
    		// sets the border attribute of tbl to 2;
    			tbl.setAttribute("border", "2");
     
    		}
    	}
    	xhr.open("GET","brded.php?dt=" + new Date().getTime(),true);
    	xhr.send(null);
    }	
     
    function delRowbr(unNom){
      var monObjet = this; 
      if(unNom != null) {
           monObjet = unNom;
      }
      var i= monObjet.parentNode.parentNode.rowIndex;
      document.getElementById('brtable').deleteRow(i);
    }
     
    </script>
     
    </head>
     
    <form method="POST" action="br2.php">
     
    	<table align="center" border = "2" cellspacing ="0" cellpadding="3" id="brtable">
    		<tr>
    		<td><b>Business Rule Type:</b></td>
    		<td><b>Dedicated:</b></td>
    		<td><input type="button" Name= "Ajouterbr" Value="ADD BR" onclick="gobr()"></td>
    		</tr>
     
    	</table>
     
    </form> 
     
     
    </body>
    </html>
    Sur IE, quand je clique sur Delete, la ligne est supprimee mais sur FF, quand je clique sur Delete, rien ne se passe. la ligne n' est pas supprimee.

    Merci d'avance de votre aide.

    Best,
    Billy

  2. #2
    Expert confirmé
    Avatar de RomainVALERI
    Homme Profil pro
    POOête
    Inscrit en
    Avril 2008
    Messages
    2 652
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : POOête

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 652
    Points : 4 164
    Points
    4 164
    Par défaut
    C'est un problème très classique et récurrent à propos de la manière dont FF et IE construisent (en l'occurrence différemment) l'arbre DOM de ta page : une petite recherche (notamment sur ce site) devrait donner beaucoup de résultats utiles ^^

  3. #3
    Expert confirmé
    Avatar de emmanuel.remy
    Inscrit en
    Novembre 2005
    Messages
    2 855
    Détails du profil
    Informations personnelles :
    Âge : 56

    Informations forums :
    Inscription : Novembre 2005
    Messages : 2 855
    Points : 4 045
    Points
    4 045
    Par défaut
    Salut,

    Je te propose cette solution vite faite et qui ne dépend de rien : à retester bien sûr ! (J'ai modifié ton code - suppression de l'aspect AJAX pour tester - mais il reste compatible avec ce que tu veux faire)

    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
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <script language="javascript">
     var bUniqueRowID = 0;
    			
    	/**
    	*  method called when the user clicks on the button
    	*/
    	
    function gobr(){
     
    			// Retrieve <table> ID and create a <tbody> element
    									
    			var tbl = document.getElementById("brtable");
    			var tblBody = document.createElement("tbody");
    			var row = document.createElement("tr");
    			
    			bUniqueRowID += 1;
    			
    			var cell_1 = document.createElement("td");
    			cell_1.align="center";
    			cell_1.valign="center";
    			var cell_2 = document.createElement("td");
    			cell_2.align="center";
    			cell_2.valign="center";
    			var cell_3 = document.createElement("td");
    			cell_3.align="center";
    			cell_3.valign="center";
     
    							
    		// Create the first cell which is a select
     
    			var cell1 = document.createElement("div");
    			cell1.innerHTML="TEXTE " + bUniqueRowID; //ici responseText
    			cell_1.appendChild(cell1);		
    								
    		//Create the second cell a checked box
    			var cell2=document.createElement("input");
    			cell2.type="checkbox";
    			cell2.name="brdedicated";
    			cell_2.appendChild(cell2);
    			
    		// Create the third cell which is a button
    			var cell3=document.createElement("input");
    			cell3.type="button";
    			cell3.value="Delete"
    			cell_3.appendChild(cell3);						
    			
    			//on ajoute les cellules SANS mettre l'événement onclick DELETE
     
    			// add cells to the row
    			row.appendChild(cell_1);
    			row.appendChild(cell_2);
    			row.appendChild(cell_3);
    
    			//on ajoute MAINTENANT le onclick sous la forme d'une fonction
    			//qui du coup connait déjà la ligne correspondante
    			cell3.onclick=delRowbr(row);
    
     
    		// add the row to the end of the table body
    			tblBody.appendChild(row);
    								
    		// put the <tbody> in the <table>
    			tbl.appendChild(tblBody);
    			
    		// sets the border attribute of tbl to 2;
    			tbl.setAttribute("border", "2");
    			
    }	
    
    //la fonction qui "fabrique" la fonction de click dédiée pour la ligne concernée
    function delRowbr(row){
      return function() {
        document.getElementById('brtable').deleteRow(row.rowIndex);
      };
    }
     
    </script>
     
    </head>
     
    <form method="POST" action="br2.php">
     
    	<table align="center" border = "2" cellspacing ="0" cellpadding="3" id="brtable">
    		<tr>
    		<td><b>Business Rule Type:</b></td>
    		<td><b>Dedicated:</b></td>
    		<td><input type="button" Name= "Ajouterbr" Value="ADD BR" onclick="gobr()"></td>
    		</tr>
     
    	</table>
     
    </form> 
     
     
    </body>
    </html>
    ERE

Discussions similaires

  1. [MySQL] Requête DELETE fonctionne en local mais pas sur le serveur
    Par abc.xyz dans le forum PHP & Base de données
    Réponses: 13
    Dernier message: 06/07/2015, 11h08
  2. [MySQL] delete fonctionnant en local mais pas sur site distant
    Par dabac dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 04/11/2010, 22h13
  3. Menu déroulant qui se déroule sur IE mais pas FF
    Par Webfab dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 10/10/2006, 14h37
  4. Changment de débit sur Windows mais pas Linux
    Par Nasky dans le forum Réseau
    Réponses: 3
    Dernier message: 29/10/2004, 11h08
  5. Programme fonctionnant sur Eclipse mais pas avec le jar?
    Par kirik dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 10/02/2004, 13h43

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