SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variables in objects??

    hi,

    This has been killing me for ages and I've had nobody to ask, is it possible to recall variables in objects. For example an img swap :

    <a href="#" onMouseOver="imgSwap('link1');"><img src=".." name="link1"></a>
    <a href="#" onMouseOver="imgSwap('link2');"><img src=".." name="link2"></a>

    .
    .
    .
    .

    function imgSwap(imgNo){

    window.[imgNo].src = 'whatever';

    }

    now I know that the eg wouldn't work but is there any way of doing something like that?

  2. #2
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I'm not quite sure what you mean, but if you accessed the object correctly, it should work:

    document.[imgNo].src = 'whatever';

    or:

    document.images.[imgNo].src = 'whatever';

    aDog

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it doesn't work for me, it comes up with an 'object expected' error.
    Last edited by DarknessAwaits; Dec 5, 2001 at 16:08.

  4. #4
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    It should be:

    document[imgNo].src = 'whatever';

    or:

    document.images[imgNo].src = 'whatever';

    There was an extra "dot" in there.

    My bad,
    aDog

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wehey! that works
    u've made me a happy man... oh god how sad that sounds...


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
  •