SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    scipt for FF & IE

    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

    then i get cell is undefined

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by svibuk View Post
    then i get cell is undefined
    The standard way that's commonly used is:

    Code javascript:
    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
        }
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by svibuk View Post
    i get error

    Error: targ.parentElement is undefined
    The parentElement object is not properly supported. Use parentNode instead, which you can see in the example code.

    Quote Originally Posted by svibuk View Post
    and in IE i get undefined alert instead of getting some cordinates
    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?

    Code javascript:
    if (typeof evt.pageX !== 'undefined') {
        ...
    } else {
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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);


    }
    }

    }

    IN FF

    i dont get any alert & noothing get executed

    in IE alert (tempX); i get undefined

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by svibuk View Post
    IN FF

    i dont get any alert & noothing get executed

    in IE alert (tempX); i get undefined
    That's because you have the parts of your if/else around the wrong way.

    If pageX is not undefined, that's when you want to use pageX, not clientX as you currently have.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok
    i will check that out now

    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

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    // var cell = targ.srcElement;
    if (targ.parentNode.grid1=="ch")
    {
    document.getElementById('H_txt').value=targ.innerText;
    var tempX, tempY;

    if (typeof targ.pageX !== 'undefined')
    {

    tempX= targ.pageX+"px";
    tempY = targ.pageY+"px";
    }
    else
    {

    tempX = targ.clientX;
    tempY = targ.clientY;
    }
    alert (document.getElementById('H_txt').value);
    alert (tempX);
    document.getElementById('H_X').value=tempX;
    document.getElementById('btnpb').click();

    }
    }
    }
    this is teh code

    in FF
    nothing happens nor do i get error in error console nor do i get any alerts
    nor any processing happens

    in IE i get teh value of alert (document.getElementById('H_txt').value);
    but alert (tempX); i get undefined
    & the button click event happens

  11. #11
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by svibuk View Post
    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
    What are your eventual plans with this?

    To do some drag and drop type of stuff with the cell, or something else?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no i dont want any drag and drop type
    currently lots of things r done but with some issues
    hope it gets cleared

    1) 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

    http://javascript-array.com/scripts/...rop_down_menu/

    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

    i hope i am clear with my query

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by svibuk View Post
    i hope i am clear with my query
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i dont get the mouse position how do i place the control in the column in which column header was cllicked

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by svibuk View Post
    if i dont get the mouse position how do i place the control in the column in which column header was cllicked
    By using the clicked header as your reference.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •