JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 7th, 2013, 07:44 PM
stephen100 stephen100 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 138 stephen100 User rank is Sergeant (500 - 2000 Reputation Level)stephen100 User rank is Sergeant (500 - 2000 Reputation Level)stephen100 User rank is Sergeant (500 - 2000 Reputation Level)stephen100 User rank is Sergeant (500 - 2000 Reputation Level)stephen100 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 53 m 56 sec
Reputation Power: 20
How to change the image?

Hi guys,

I need your help, I want to change the image using with a javascript when i press on the up and down keyboard arrow button.


Code:
<html>
<body>


<style type="text/css">
 
body {background:url('images/blue_background.jpg') no-repeat center center fixed;}
 
</style>


<div id="image1" style="position:absolute; overflow:hidden; left:415px; top:157px; width:114px; height:81px; z-index:0"><img src="/images/image_blue.jpg" alt="" title="" border=0 width=114 height=81></div>


<script>

document.onkeydown = checkKey;

function checkKey(e) {

    e = e || window.event;

    if (e.keyCode == '38') {
    
       var path ="/images/image_blue.jpg";
       
         if(document.getElementById("image1").src="/images/image_blue.jpg") {
            document.getElementById("image1").innerHTML=.src="/images/image_yellow.jpg";
         }
         else {
           document.getElementById("image1").src="/images/image_blue.jpg";
}
    }
    else if (e.keyCode == '40') {
        window.alert('down arrow')
    }
}

</script>


</body>
</html>



When I press on the keyboard, it doesn't change the image.

Does anyone know how i can do this?

thanks in advance

Reply With Quote
  #2  
Old March 7th, 2013, 08:46 PM
richpri's Avatar
richpri richpri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Chicago
Posts: 51 richpri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 32 sec
Reputation Power: 1
Facebook
I am confused by the inconsistent assignments in your if and else clauses.
What is the ".innerHTML=.src=" all about. Shouldn't it be one or the other.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > How to change the image?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap