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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Location
    Pennsylvania, USA
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Tell me what's wrong

    I have a pretty simple javascript on my site. I'm not the best with Javascript, so could someone tell me what is wrong. Here's the Javascript.
    Code:
    <script language="Javascript" type="text/javascript">
    <!--
    function viewpic(A,B,C)
    	{
    	 document.getElementByName("bigpicture").src=A
    	 document.getElementByName("bigpicture").alt=B
    	 document.getElementById("descriptiondiv").innerHTML="<p>" + C + "</p>"
    	}
    //-->
    </script>
    My HMTL (condensed) is:
    Code:
    <a href="Javascript:viewpic(images/me.jpg,Picture of Me,This is a picture of me.)">Picture of me</a>
    <br><br>
    <img src="images/something.jpg" name="bigpicture" alt="picture"><br>
    <div id="descriptiondiv"></div>
    What is supposed to happen is - you click on the link that says Picture of Me (actually there will be lots of pictures) and the image by the name of "bigpicture" should change it's source and alternate text. Also a small description will get put in the div. It doesn't do any of that, and my FireFox Javascript Console didn't give me any error message, so I'm not sure what's wrong. Please help me out.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    There is no getElementByName method but getElementsByName and getElementsByTagName. But you won't need them.

    document.images["bigpicture"].src=A

    or if you give an id to the image.

    document.getElementById("bigpicture").src=A
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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