SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically writing this variable so it gets executed

    Hi,

    I'm trying to dynamically write out this line of javascript:

    obj.offsetLeft


    So I want to be able to feed a param of either Top or Left in and then write it out so it gets execuated correctly in the javascript....so i've tried stuff like:

    function findPos(axis) {
    obj.offset[axis]


    and

    function findPos(axis) {
    obj.offset+[axis]

    where axis is either Left or Top


    but it's not working....any ideas?
    Last edited by elduderino; May 1, 2009 at 00:57. Reason: spell check

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    function findPos(axis) {
        obj['offset' + axis];
    }
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Jimmy,

    hmm tried that befiore and it didn't work....although if i actually do :

    function findPos(axis) {
    obj['offsetLeft'];
    }

    it works

    i've alerted axis out just before and it's definitely 'Left'.

    Weird!

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    evne if I do:

    var i = 'offset'+axis;
    alert(i);
    curleft += obj[i];

    the alert gives me 'offsetLeft'...it still does not work

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's ok sorted it now...many thanks


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
  •