function test(evt)
{
if (document.all)
{
var cell = event.srcElement;
}
else
{
var cell = evt.srcElement;
}
if (cell.parentElement.grid1=="ch")
{
}
}
i have teh above function
if i just usse
var cell = event.srcElement; i get errro in FF as event not defined
but if i use the above function with if (document.all) and all
function test(evt) {
evt = evt || window.event;
var targ = evt.target || evt.srcElement;
if (targ.nodeType === 3) { // is text element
targ = targ.parentNode(); // fix Opera bug
}
if (targ.nodeType === 1) { // is node element
// do stuff here
}
}
i get error function test(evt)
{
evt = evt || window.event;
var targ = evt.target || evt.srcElement;
if (targ.nodeType === 3)
{ // is text element
targ = targ.parentNode(); // fix Opera bug
}
if (targ.nodeType === 1)
{ // is node element
// do stuff here
// var cell = targ.srcElement;
if (targ.parentElement.grid1=="ch")
{
document.getElementById('H_text').value=targ.innerText;
var tempX, tempY;
if (document.all)
{
tempX = targ.clientX;
tempY = targ.clientY;
}
else
{
tempX= evt.pageX+"px";
tempY = evt.pageY+"px";
}
document.getElementById(‘H_X’).value=tempX;
}
}
}
Error: targ.parentElement is undefined
Source
and in IE i get undefined alert instead of getting some cordinates
The parentElement object is not properly supported. Use parentNode instead, which you can see in the example code.
Also, instead of checking for document.all, it’s better to check if the non-IE property exists and to use that. If it doesn’t, you can use the iE property instead?
function test(evt)
{
evt = evt || window.event;
var targ = evt.target || evt.srcElement;
if (targ.nodeType === 3)
{ // is text element
targ = targ.parentNode(); // fix Opera bug
}
if (targ.nodeType === 1)
{
// var cell = targ.srcElement;
if (targ.parentNode.grid1==“ch”)
{
document.getElementById(‘H_text’).value=targ.innerText;
var tempX, tempY;
if (typeof evt.pageX !== ‘undefined’)
{
tempX = targ.clientX;
tempY = targ.clientY;
}
else
{
tempX= evt.pageX+“px”;
tempY = evt.pageY+“px”;
}
document.getElementById(‘H_X’).value=tempX;
alert(document.getElementById(‘H_text’).value);
alert (tempX);
secondaly i wanted to know how do i get the cordinates
currently i get the cordinates of the screen click ie X & Y
instead of the getting the screen coordinates when clicked in need to get the coordinates /position of the cell which is clicked
i have table with columns & i clcik the table header cell
need cordinates of it
You may want to use info from http://www.quirksmode.org/js/events_properties.html which gives you the mouse coordinates relative to the document.
From there, you can get the element position in realation to the document, and ate the difference to get the mouse position in relation to the element itself.
You may want to use info from http://www.quirksmode.org/js/events_properties.html which gives you the mouse coordinates relative to the document.
From there, you can get the element position in realation to the document, and ate the difference to get the mouse position in relation to the element itself.
function test(evt) {
evt = evt || window.event;
var targ = evt.target || evt.srcElement;
if (targ.nodeType === 3) { // is text element
targ = targ.parentNode(); // fix Opera bug
}
if (targ.nodeType === 1) { // is node element
function doSomething(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
document.getElementById(‘btnpb’).click();
}
in window.onload function i have
document.getElementById(‘grid’).onmousedown = doSomething
here th eproblem is even if i use scroll back the function gets activated
i just want that when the cell is clciked the function shld get activated
i tried with .onclcik event
but nothing happens
no i dont want any drag and drop type
currently lots of things r done but with some issues
hope it gets cleared
FF issue i mean the script that i have doesnot work with FF
2)i have a grid with few columns & the grid has scroll bar
the grid does not fit in one screen so need to scroll the browser
when a grid header column is clicked a div control gets displayed nr that column & works fine with browser scroll
when the browser is scrolled the div control moves with the column
but if i use the grid scroll bar the div control doesnot move with the column
hope the query/issues r clear
in short
i found a sample at
my requirement is similar but with a difference that i have only one div
here they have a menu bar in my case its table header cells
which when clicked i get the header cell content by javascript
i have only one div which shlould be displaced on the header cell click
rest all things needs to be done with data from database
Yes indeed. It seems that you have no need to know the mouse position at all, and instead are intend on using the header cells to provide sorted information.