Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts

    Photo/caption swap function not functioning

    When a user rolls over a thumbnail the image with the ID 'placeholder' should change and the text with the ID 'caption' should change. The images are preloaded. I can't see my flaw. Here's my function:

    function showProject (whichProject)
    if (document.getElementById) {
    document.getElementById('placeholder').src = whichProject.src;
    if (whichProject.title) {
    document.getElementById('caption').childNodes[0].nodeValue = whichProject.title;
    }
    else {
    document.getElementById('caption').childNodes[0].nodeValue = whichPhoto.childNodes[0].nodeValue;
    }
    return false;
    }
    else {
    return true;
    }
    }
    \0\0
    He!\0\0pف\0pف\0oad (pared down):

    if (document.images) {
    niche = new Image;
    niche.src = 'images/more/niche.jpg';
    }

    Here's my line item:

    <A onMouseOver="javascript:showProject('niche')" HREF="more_niches.html"
    TITLE="Large kitchen niche"><IMG SRC="images/more/niche_large_t.jpg"></A>
    Last edited by marilynn.fowler; 06-02-2006 at 08:28 PM. Reason: cut off my entry, then replaced text with random text

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    there is no src or title property of a string.

    whichProject has a value of 'niche' which is a string.

    Perhaps your thinking that the string 'niche' relates to something else further up or down in your javascript or your markup. Could you paste more of your code if you need more assistance?

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts

    Eureka!

    I actually figured it out! With my own brain!
    I broke it into two functions and called them both with onMouseOver.

    if (document.images) {
    \0 foué\0\0hځ\0hځ\0Image();
    fountain.src = 'images/more/fountain.jpg';
    fountaintext = 'Fountain';

    function chgImg(imgField,newImg) {
    if (document.images) {
    document[imgField].src= eval(newImg + ".src")
    }
    }

    function chgCaption(whichCaption) {
    if (document.getElementById) {
    document.getElementById('caption').childNodes[0].nodeValue = whichCaption;
    }
    }

    <A onMouseOver="chgImg('placeholder','fountain'); chgCaption(fountaintext); return true;"
    HREF="more_fountain.html"><IMG SRC="images/more/fountain_t.jpg" NAME="fountain"></A>
    \0\0
    3 questions: will leaving out 'var' hurt it, and is there any way to combine it into one function that evaluates it by the NAME attribute? And why do my entries to this forum keep getting truncated/garbledè
    Last edited by marilynn.fowler; 06-02-2006 at 09:17 PM. Reason: it keeps truncating my entry

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Gratz on figuring it out yourself!

    Why your posts get truncated, no idea. Perhaps foreign keyset?

    Anyway, the VAR keyword is used to declare variables before their use. It is good practice and will produce javascript warnings in strict mode. I would use them.

    How can you make something key of an attribute of the element?

    <img name="fountain" onmouseover="func(this.name);" />

    How can you make it call 1 function?

    Code:
    function func(name)
    {
      func1();
      func2();
    }
    Hope that helps.


  •  

    Posting Permissions

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