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 to the CF scene
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SRC value in forms

    I have a program with an form and an input that is an image. i want to be able to change the image after a function is activated but i dont know how to do this with javascript

    function change(){
    document.a.b.src = "something.jpg"
    }


    <form name="a">
    <input name="b" type="image" src="x.x">
    <input name="c" type="button" value="click" onclick="change()">
    </form>

    basically when that button is clicked i want that function to set the src to an actual image. Thanks in advance for any help

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Here you are:-

    Code:
    <div id = "div1"><img src="One.gif" id = "theImage"></div>
    <br>
    <input name="c" type="button" value="Click to change image" onclick="change()">
    
    <script type = "text/javascript">
    function change(){
    document.getElementById("theImage").src="Two.gif";
    }
    </script>

    BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.


  •  

    Posting Permissions

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