Recuperation de l'ID D'un DIV
Bonjour,
Un probleme qui a l'air simple. j'ai un DIV et je veux recuperer par $_GET les valeurs du click de ma asouris et l'ID du DIV. Pour le click ca marche mais j'arrive pas a recuperer l'ID du DIV ... Pouvez vous m'aider. Merciiiiiiii
LE JAVASCRIPT
---------------------------------------------
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<script>
function sourisxy(id,e)
{
id = document.getElementById('id');
x = (navigator.appName=="Netscape") ? e.pageX : event.x + document.body.scrollLeft;
y = (navigator.appName=="Netscape") ? e.pageY : event.y + document.body.scrollTop;
// alert("x:"+x+" y:"+y);
window.location.href="test_tableau.php?x="+x +"&y="+y +"&id="+id;
}
if(navigator.appName.substring(0,3) == "Net")
document.captureEvents(Event.mousemove);
document.onclick = sourisxy;
</script> |
LE DIV
--------------------------------
Code:
1 2 3 4 5 6
|
<div id="id1" onclick="sourisxy(id1,e)" style="z-index: 1; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 125px; border: 1px dashed #900; background-color: red;position:relative;">
<div id="id2" onclick="sourisxy(id2,e)" style="z-index: 2; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 50px; border: 1px dashed #900; background-color: yellow;position:absolute; top:50px;"></div>
<div id="id3" onclick="sourisxy(id3,e)" style="z-index: 3; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 25px; border: 1px dashed #900; background-color: green;position:absolute; |
Merciii mais toujours un pb id=undefined
Ca me renvoi id=undefined .. une idée
Merci de votre aide en tout cas
je remet le code corrigé :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
<script>
function sourisxy(obj,e)
{
id = this.id;
x = (navigator.appName=="Netscape") ? e.pageX : event.x + document.body.scrollLeft;
y = (navigator.appName=="Netscape") ? e.pageY : event.y + document.body.scrollTop;
// alert("x:"+x+" y:"+y);
window.location.href="test_tabkeau.htm?x="+x +"&y="+y +"&id="+id;
}
if(navigator.appName.substring(0,3) == "Net")
document.captureEvents(Event.mousemove);
document.onclick = sourisxy;
</script> |
et les DIV
--------------------------
Code:
1 2 3 4 5
|
<div id="id1" onclick="sourisxy(this,e);" style="z-index: 1; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 125px; border: 1px dashed #900; background-color: red;position:relative;">
<div id="id2" onclick="sourisxy(this,e);" style="z-index: 2; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 50px; border: 1px dashed #900; background-color: yellow;position:absolute; top:50px;"></div>
<div id="id3" onclick="sourisxy(this,e);" style="z-index: 3; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 25px; border: 1px dashed #900; background-color: green;position:absolute; top:25px;"></div> |
un petit peu plus ... ;-)
Heu je ne crois pas que mon javascript soit à ce niveau.
C'est à dire je dois mettre quoi ou ?
Merci de ton aide ......
Je sais que j'insiste mais c'est comme une bouée de sauvetage
Alors j'ai une erreur à la ligne rouge "objet attendu".
Si il te reste une idée dans les cartons je prends. Merci de ton ecoute.
Je te met tout mon code pour tester eventuellement.
MERCIIIIIIIIIIIIIIIIIIII
Code:
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
|
<!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">
<head>
<style type="text/css">.Style8 {font-size: 10px; font-family: Arial, Helvetica, sans-serif; }</style>
<script>
function sourisxy(obj,e)
{
id = obj.id;
x = (navigator.appName=="Netscape") ? e.pageX : event.x + document.body.scrollLeft;
y = (navigator.appName=="Netscape") ? e.pageY : event.y + document.body.scrollTop;
window.location.href="test3.html?x="+x +"&y="+y +"&id="+id;
}
if(navigator.appName.substring(0,3) == "Net")
document.body.captureEvents(Event.mousemove);
document.body.onclick = sourisxy;
</script>
</head>
<body onload="init()">
<div id="id1" onclick="sourisxy(this,e);" style="z-index: 1; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 125px; border: 1px dashed #900; background-color: red;position:relative;">
<div id="id2" onclick="sourisxy(this,e);" style="z-index: 2; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 50px; border: 1px dashed #900; background-color: yellow;position:absolute; top:50px;"></div>
<div id="id3" onclick="sourisxy(this,e);" style="z-index: 3; margin-left: 0px; margin-top: 0px; opacity: 1; width: 160px; height: 25px; border: 1px dashed #900; background-color: green;position:absolute; top:25px;"></div>
</div>
</body>
</html> |