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 3 of 3

Thread: Newbie Question

  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Newbie Question

    Hey guys,
    I'm very new to JavaScript programming and so I wrote this function today to try and change the image with a simple click of a button. Code:

    Code:
    <html>
    <head>
    <title>Testing Javascript</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function changeimage() {
    	var img = document.getElementById("Myimage");
        img.src="newimage.png";	
    }
    // -->
    </script>
    </head>
    <body>
    <img src="myimage.png" name="Myimage" ID="Myimage">
    
    <form name="changeimage">
    <input type="button" value="Change Image" onClick="changeimage();">
    </form>
    </body>
    </html>
    But for some reason this does nothing :X Could someone explain what is wrong :X? Thanks!

  • #2
    New Coder
    Join Date
    Apr 2005
    Location
    Massachusetts, US
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts
    This isn't exactly what you're trying to do, but maybe this will help you out?

    http://www.javascript-coder.com/butt...utton-p1.phtml
    Last edited by Forever Zero; 06-18-2008 at 05:49 PM.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    <form name="changeimage">
    <input type="button" value="Change Image" onClick="changeimage();">
    </form>
    Use two different names for your form and function

    PS: A form is not actually required to use a button
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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