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 :

int�raction entre deux scripts


Sujet :

JavaScript

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre confirm�
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    127
    D�tails du profil
    Informations personnelles :
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Avril 2005
    Messages : 127
    Par d�faut int�raction entre deux scripts
    Bonjour,

    J'ai un probl�me que je n'arrive pas � r�soudre tout seul...

    J'ai une page qui charge plusieurs script et 2 d'entre eux ont du mal � s'accepter l'un et l'autre .
    En fait ma page custom-form-elements.js emp�che la page filtre_equipe.js de se charger, c'est-�-dire que le script filtre_equipes.js ne fonctionne pas si custom-form-elements.js est charg�. Lorsque je met custom-form-elements.js en commentaire filtre_equipe.js fonctionne parfaitement.

    Voici le script custom-form_elements.js qui est utilis� afin de "styliser" mes select/bouton-radio/checkbox html :
    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
     
    var checkboxHeight = "25";
    var radioHeight = "25";
    var selectWidth = "190";
     
    document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');
     
    var Custom = {
    	init: function() {
    		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
    		for(a = 0; a < inputs.length; a++) {
    			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
    				span[a] = document.createElement("span");
    				span[a].className = inputs[a].type;
     
    				if(inputs[a].checked == true) {
    					if(inputs[a].type == "checkbox") {
    						position = "0 -" + (checkboxHeight*2) + "px";
    						span[a].style.backgroundPosition = position;
    					} else {
    						position = "0 -" + (radioHeight*2) + "px";
    						span[a].style.backgroundPosition = position;
    					}
    				}
    				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
    				inputs[a].onchange = Custom.clear;
    				if(!inputs[a].getAttribute("disabled")) {
    					span[a].onmousedown = Custom.pushed;
    					span[a].onmouseup = Custom.check;
    				} else {
    					span[a].className = span[a].className += " disabled";
    				}
    			}
    		}
    		inputs = document.getElementsByTagName("select");
    		for(a = 0; a < inputs.length; a++) {
    			if(inputs[a].className == "styled") {
    				option = inputs[a].getElementsByTagName("option");
    				active = option[0].childNodes[0].nodeValue;
    				textnode = document.createTextNode(active);
    				for(b = 0; b < option.length; b++) {
    					if(option[b].selected == true) {
    						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
    					}
    				}
    				span[a] = document.createElement("span");
    				span[a].className = "select";
    				span[a].id = "select" + inputs[a].name;
    				span[a].appendChild(textnode);
    				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
    				if(!inputs[a].getAttribute("disabled")) {
    					inputs[a].onchange = Custom.choose;
    				} else {
    					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
    				}
    			}
    		}
    		document.onmouseup = Custom.clear;
    	},
    	pushed: function() {
    		element = this.nextSibling;
    		if(element.checked == true && element.type == "checkbox") {
    			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
    		} else if(element.checked == true && element.type == "radio") {
    			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
    		} else if(element.checked != true && element.type == "checkbox") {
    			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
    		} else {
    			this.style.backgroundPosition = "0 -" + radioHeight + "px";
    		}
    	},
    	check: function() {
    		element = this.nextSibling;
    		if(element.checked == true && element.type == "checkbox") {
    			this.style.backgroundPosition = "0 0";
    			element.checked = false;
    		} else {
    			if(element.type == "checkbox") {
    				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
    			} else {
    				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
    				group = this.nextSibling.name;
    				inputs = document.getElementsByTagName("input");
    				for(a = 0; a < inputs.length; a++) {
    					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
    						inputs[a].previousSibling.style.backgroundPosition = "0 0";
    					}
    				}
    			}
    			element.checked = true;
    		}
    	},
    	clear: function() {
    		inputs = document.getElementsByTagName("input");
    		for(var b = 0; b < inputs.length; b++) {
    			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
    			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 0";
    			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
    			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 0";
    			}
    		}
    	},
    	choose: function() {
    		option = this.getElementsByTagName("option");
    		for(d = 0; d < option.length; d++) {
    			if(option[d].selected == true) {
    				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
    			}
    		}
    	}
    }
    window.onload = Custom.init;
    Et voici le code de filtre_equipes.js qui est utilis� afin d'envoyer la valeur d'un select (POST) pour rafra�chir un tableau
    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
     
    function getXhr(){
    	var xhr = null; 
    	if(window.XMLHttpRequest) // Firefox et autres
    		xhr = new XMLHttpRequest(); 
    	else 
    		if(window.ActiveXObject){ // Internet Explorer 
    			try {
    				xhr = new ActiveXObject("Msxml2.XMLHTTP");
    			} catch (e) {
    				xhr = new ActiveXObject("Microsoft.XMLHTTP");
    			  }
    		}
    		else { // XMLHttpRequest non supporté par le navigateur 
    			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
    			xhr = false; 
    		} 
    	return xhr
    }
     
    /*
    	Fonction qui récupère les valeurs des filtres (select)
    	et utilise la page tableau_equipe.php pour rafraîchir la liste des équipes
    */			
    function tableau_equipes(){
    	var xhr = getXhr();
    	xhr.onreadystatechange = function(){
    		if(xhr.readyState == 4 && xhr.status == 200){
    			leselect = xhr.responseText;
    			document.getElementById('liste_equipe').innerHTML = leselect;
    		}
    	}
     
    	xhr.open("POST","test.php",true);
    	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    	// l'id du pays
    	sel = document.getElementById('nation');
    	id_pays = sel.options[sel.selectedIndex].value;
    	xhr.send("id_pays="+id_pays);
     
    }
    Helllllpppppp .

  2. #2
    R�dacteur/Mod�rateur

    Avatar de SpaceFrog
    Homme Profil pro
    D�veloppeur Web Php Mysql Html Javascript CSS Apache - Int�grateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 659
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 75
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activit� : D�veloppeur Web Php Mysql Html Javascript CSS Apache - Int�grateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 659
    Billets dans le blog
    1
    Par d�faut
    ha ben vu comme �a c'est diff�rent, rien a vois avec des conflits de variables ...
    c'est juste le document write ...
    Ma page Developpez - Mon Blog Developpez
    Pr�sident du CCMPTP (Comit� Contre le Mot "Probl�me" dans les Titres de Posts)
    Deux r�gles du succ�s: 1) Ne communiquez jamais � quelqu'un tout votre savoir...
    Votre post est r�solu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de D�veloppez !

  3. #3
    Membre confirm�
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    127
    D�tails du profil
    Informations personnelles :
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Avril 2005
    Messages : 127
    Par d�faut
    Citation Envoy� par SpaceFrog Voir le message
    ha ben vu comme �a c'est diff�rent, rien a vois avec des conflits de variables ...
    c'est juste le document write ...
    Pourtant non...

    Voici le code de ma page test (ici cela fonctionne car la feuille custom-form-elements.js est mis en commentaire) :
    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
     
    <?php
    include('fonction.php');
    $connexion=connexion();
    session_start();
     
    ?>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    	<head>
     
     
    		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
     
    		<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
    		<script type="text/javascript" src="/js/filtre_equipe.js"></script>
    		<!--
    		<script type="text/javascript" src="/js/custom-form-elements.js"></script>
    		-->
    		<style type="text/css">
    			.select {
    				position: absolute;
    				width: 158px; /* With the padding included, the width is 190 pixels: the actual width of the image. */
    				height: 21px;
    				padding: 0 24px 0 8px;
    				color: #fff;
    				font: 12px/21px arial,sans-serif;
    				background: url(../img/select.png) no-repeat;
    				overflow: hidden;
    			}
    		</style>
     
     
    	</head>
    	<body>
    		<select class="styled" name="type" id="type" onchange="tableau_equipes()">
    			<option value="-1" selected>Filtre par type</option>
    			<option value="C">Club</option>
    			<option value="N">National</option>
    		</select>
     
    		<div id="liste_equipe"></div>
    	</body>
    </html>
    Le code de la page test.php qui �crit le texte :
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
     
    <?php
     
    echo 'type : '.$_POST['type'];
    ?>
    Le code de custom-form-elements.js
    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
     
    /*
     
    CUSTOM FORM ELEMENTS
     
    Created by Ryan Fait
    www.ryanfait.com
     
    The only things you may need to change in this file are the following
    variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)
     
    The numbers you set for checkboxHeight and radioHeight should be one quarter
    of the total height of the image want to use for checkboxes and radio
    buttons. Both images should contain the four stages of both inputs stacked
    on top of each other in this order: unchecked, unchecked-clicked,
    checked, checked-clicked.
     
    You may need to adjust your images a bit if there is a slight vertical
    movement during the different stages of the button activation.
     
    The value of selectWidth should be the width of your select list image.
     
    Visit http://ryanfait.com/ for more information.
     
    */
     
    var checkboxHeight = "25";
    var radioHeight = "25";
    var selectWidth = "190";
     
    document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');
     
    var Custom = {
    	init: function() {
    		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
    		for(a = 0; a < inputs.length; a++) {
    			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
    				span[a] = document.createElement("span");
    				span[a].className = inputs[a].type;
     
    				if(inputs[a].checked == true) {
    					if(inputs[a].type == "checkbox") {
    						position = "0 -" + (checkboxHeight*2) + "px";
    						span[a].style.backgroundPosition = position;
    					} else {
    						position = "0 -" + (radioHeight*2) + "px";
    						span[a].style.backgroundPosition = position;
    					}
    				}
    				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
    				inputs[a].onchange = Custom.clear;
    				if(!inputs[a].getAttribute("disabled")) {
    					span[a].onmousedown = Custom.pushed;
    					span[a].onmouseup = Custom.check;
    				} else {
    					span[a].className = span[a].className += " disabled";
    				}
    			}
    		}
    		inputs = document.getElementsByTagName("select");
    		for(a = 0; a < inputs.length; a++) {
    			if(inputs[a].className == "styled") {
    				option = inputs[a].getElementsByTagName("option");
    				active = option[0].childNodes[0].nodeValue;
    				textnode = document.createTextNode(active);
    				for(b = 0; b < option.length; b++) {
    					if(option[b].selected == true) {
    						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
    					}
    				}
    				span[a] = document.createElement("span");
    				span[a].className = "select";
    				span[a].id = "select" + inputs[a].name;
    				span[a].appendChild(textnode);
    				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
    				if(!inputs[a].getAttribute("disabled")) {
    					inputs[a].onchange = Custom.choose;
    				} else {
    					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
    				}
    			}
    		}
    		document.onmouseup = Custom.clear;
    	},
    	pushed: function() {
    		element = this.nextSibling;
    		if(element.checked == true && element.type == "checkbox") {
    			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
    		} else if(element.checked == true && element.type == "radio") {
    			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
    		} else if(element.checked != true && element.type == "checkbox") {
    			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
    		} else {
    			this.style.backgroundPosition = "0 -" + radioHeight + "px";
    		}
    	},
    	check: function() {
    		element = this.nextSibling;
    		if(element.checked == true && element.type == "checkbox") {
    			this.style.backgroundPosition = "0 0";
    			element.checked = false;
    		} else {
    			if(element.type == "checkbox") {
    				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
    			} else {
    				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
    				group = this.nextSibling.name;
    				inputs = document.getElementsByTagName("input");
    				for(a = 0; a < inputs.length; a++) {
    					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
    						inputs[a].previousSibling.style.backgroundPosition = "0 0";
    					}
    				}
    			}
    			element.checked = true;
    		}
    	},
    	clear: function() {
    		inputs = document.getElementsByTagName("input");
    		for(var b = 0; b < inputs.length; b++) {
    			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
    			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 0";
    			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
    			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
    				inputs[b].previousSibling.style.backgroundPosition = "0 0";
    			}
    		}
    	},
    	choose: function() {
    		option = this.getElementsByTagName("option");
    		for(d = 0; d < option.length; d++) {
    			if(option[d].selected == true) {
    				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
    			}
    		}
    	}
    }
    window.onload = Custom.init;
    Le code de filtre_equipe.js :
    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
     
    function getXhr(){
    	var xhr = null; 
    	if(window.XMLHttpRequest) // Firefox et autres
    		xhr = new XMLHttpRequest(); 
    	else 
    		if(window.ActiveXObject){ // Internet Explorer 
    			try {
    				xhr = new ActiveXObject("Msxml2.XMLHTTP");
    			} catch (e) {
    				xhr = new ActiveXObject("Microsoft.XMLHTTP");
    			  }
    		}
    		else { // XMLHttpRequest non supporté par le navigateur 
    			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
    			xhr = false; 
    		} 
    	return xhr
    }
     
    /*
    	Fonction qui récupère les valeurs des filtres (select)
    	et utilise la page tableau_equipe.php pour rafraîchir la liste des équipes
    */			
    function tableau_equipes(){
    	var xhr = getXhr();
    	xhr.onreadystatechange = function(){
    		if(xhr.readyState == 4 && xhr.status == 200){
    			leselect = xhr.responseText;
    			document.getElementById('liste_equipe').innerHTML = leselect;
    		}
    	}
     
    	xhr.open("POST","test.php",true);
    	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    	// le type d'équipe
    	sel = document.getElementById('type');
    	type = sel.options[sel.selectedIndex].value;
    	xhr.send("type="+type);
     
    }
    Je suis vraiment perdu sur ce probl�me, je ne vois absolument pas ce qui bloque...

  4. #4
    Membre confirm�
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    127
    D�tails du profil
    Informations personnelles :
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Avril 2005
    Messages : 127
    Par d�faut
    Ah trouv� . Il fallait faire appel � la fonction qui rafra�chit le div dans la page custom-form-elements.js.

    Merci tout de m�me pour l'aide apport�e.

  5. #5
    Membre confirm�
    Inscrit en
    Novembre 2007
    Messages
    57
    D�tails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 57
    Par d�faut
    Citation Envoy� par @po�alypse Voir le message
    Ah trouv� . Il fallait faire appel � la fonction qui rafra�chit le div dans la page custom-form-elements.js.

    Merci tout de m�me pour l'aide apport�e.
    Bonjour,

    je pense que je suis un probl�me qui ressemble au tien, j'essaie de recharger le
    custom-form-elements.js avec la fonction "Custom.init" apr�s une requete AJAX mais sans succ�s, peut-tu m'aider stp

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. [MooTools] Conflit entre deux scripts utilisant du Mootools
    Par kurkaine dans le forum Biblioth�ques & Frameworks
    R�ponses: 6
    Dernier message: 24/02/2011, 19h59
  2. int�raction entre deux formulaires
    Par radahm dans le forum IHM
    R�ponses: 7
    Dernier message: 05/03/2009, 15h10
  3. Conflit entre deux script javascript
    Par Tyrael62 dans le forum G�n�ral JavaScript
    R�ponses: 2
    Dernier message: 18/06/2008, 09h39
  4. compatibilit� entre deux scripts
    Par stars333 dans le forum G�n�ral JavaScript
    R�ponses: 0
    Dernier message: 12/02/2008, 19h46
  5. Probl�me de compatibilit� entre deux scripts
    Par frutix dans le forum G�n�ral JavaScript
    R�ponses: 2
    Dernier message: 20/01/2006, 14h24

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