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 8 of 8
  1. #1
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Not quite sure what the problem is

    Code:
            <script language="javascript" type="text/javascript">
            function previewimage(imagename) {
                document.getElementById("preview-image").src="uploads/previews/" . imagename;
            }
            </script>
    Hi there. I have this piece of coding sitting in the head coding of my website. I'm unsure of any syntax errors in it, but I do know that it's not working when called upon like this:

    Code:
            <div id="recent-rotator">
    
              <div id="selection">
                <a href="entry/?id=2" onmouseover="previewimage(2.png)">Two</a>
                <a href="entry/?id=1" onmouseover="previewimage(1.png)">One</a>
              </div>
    
              <div id="selected"><img id="preview-image" src="uploads/previews/2.png" alt="Two"/></div>
            </div>
    I honestly, cannot figure out what's wrong with it. I bet that it's something simple. I've checked directories etc and they are fine, but I can't work out why it won't change image upon mouse over. I don't use Javascript a lot so any help would be nice.

    Thank you
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    <script type="text/javascript">
            function previewimage(imagename) {
                document.getElementById("preview-image").src="uploads/previews/" + imagename;
            }
            </script>
    Tourist in hotel in Jasper, Canada: "Do we need to convert our Canadian currency into British pounds when we go on to British Columbia?"

  • #3
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thank you. ^_^

    I've forgotten the basics of javascript - Too much PHP.
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #4
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hmmm still not working, is it possible, that there is something else that could be stopping it from changing?
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts

  • #6
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I experiemented with the script, and I've put it down to javascript syntax when calling on the variable from the function parameters - is there a better way to write this?
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Try:-

    src='"uploads/previews/" + imagename';

  • #8
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    This is probably a problem:
    Code:
    onmouseover="previewimage(2.png)"
    Should be:
    Code:
    onmouseover="previewimage('2.png')"


  •  

    Posting Permissions

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