Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,255 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,186 people online right now. Registration is fast and FREE... Join Now!




help changing image.

 
Reply to this topicStart new topic

help changing image.

inc0mplete
13 Oct, 2008 - 09:17 AM
Post #1

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 22

Hi! I am trying to change the image, but it doesn't seem to work. I don't know why. Here is my code, any help would be great. Thanks!
CODE

<html>
<head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>velo2</title>
    <link rel="stylesheet" href="velo.css" type="text/css">
    <script type="text/javascript">
        function change(img_name){
            var update_name = "velo/"+img_name;
            document.image.src=update_name;
        }
    </script>
</head>

<body>
    <script type="text/javascript">
    var test="velo/" + "headerimg_2.jpg";
    </script>
<div class="container">
<div class="menu">
<ul>
<li><a href="velo2.html" class="about"></a></li>
<li><a href="#" id="menu2" class="menu2" onClick="change(headerimg2_jpg)" ></a></li>
<li><a href="#" id="wine" class="wine"></a></li>
<li><a href="#" id="events" class="events"></a></li>
<li><a href="#" id="press" class="press"></a></li>
<li><a href="#" id="contact" class="contact"></a></li>
<li><a href="#" id="directions" class="directions"></a></li>
</ul>
</div>

User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Help Changing Image.
13 Oct, 2008 - 02:27 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,020



Thanked: 81 times
Dream Kudos: 1175
My Contributions
Well, in the code you provided you don't actually have an image anywhere, which is probably the reason you don't see any update when you call the function.

Additionally hyou have the issue that you are sending the parameters to the function as if it was a variable name, not a string. Then you are calling document.image, but that doesn't mean anythin either.

Try something more like so:

CODE
<html>
<head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>velo2</title>
    <link rel="stylesheet" href="velo.css" type="text/css">
    <script type="text/javascript">
        function change(id, newSrc){
            obj = document.getElementById(id);
            var update_name = "velo/"+newSrc;
            obj.src = update_name;
        }
    </script>
</head>

<body>
    <script type="text/javascript">
    var test="velo/" + "headerimg_2.jpg"; // THIS CODE DOES NOTHING
    </script>
<div class="container">
<img id="TEST_ID" src="" />
<div class="menu">
<ul>
<li><a href="velo2.html" class="about"></a></li>
<li><a href="#" id="menu2" class="menu2" onClick="change('headerimg2_jpg', 'TEST_ID')" ></a></li>
<li><a href="#" id="wine" class="wine"></a></li>
<li><a href="#" id="events" class="events"></a></li>
<li><a href="#" id="press" class="press"></a></li>
<li><a href="#" id="contact" class="contact"></a></li>
<li><a href="#" id="directions" class="directions"></a></li>
</ul>
</div>



HTH
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:27AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month