Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

add java script to html

Name: Anonymous 2009-05-01 7:20

how can i add java script to html? this way it doesn't work:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>aa</title>
</head>
<body>
<img style="width: 117px; height: 37px;" alt=""
 src="buttons/shop1.png" id="shop">
<script type="text/javascript">
var x = 0
var y = 0
var shop = document.getElementById("shop-img");
onMousedown = mouseDown();
onMouseup = mouseUp();
onMouseout = mouseOut();
onMouseover = mouseOver();
onMousedown = mouseDown();
function mouseDown()
{
shop.src = 'buttons/shop3.png';
}
function mouseUp()
{
shop.src = 'buttons/shop4.png';
var x = 1; var y = 1;
}
function mouseOut()
{
if (x == 2) {
shop.src='buttons/shop4.png';
} else {
shop.scr='buttons/shop1.png'; }
}
function mouseOver()
{
if (y == 2){
shop.src='buttons/shop3.png';
} else {
shop.src='buttons/shop2.png';
} }
</script>
</body>
</html>

Name: Anonymous 2009-05-01 16:57

Besides being perversely awful code, my guess of what problem you want identified is this section:
var shop = document.getElementById("shop-img");
onMousedown = mouseDown();
onMouseup = mouseUp();
onMouseout = mouseOut();
onMouseover = mouseOver();
onMousedown = mouseDown();

Code in the <head> of your document is executed before the DOM is loaded, so "shop-img" doesn't actually exist in the context of the script when it is running. You can fix this by attaching your code to a window.onload event, or using the better jQuery alternative $(document).ready(function() { ... As well as that, the next four lines of code don't actually do anything- and may throw errors as well. "onMousedown" in your code is being treated as an lvalue, so what is happening is the local variable "onMouseDown" is being assigned a function pointer, and itself becomes a function. If you were looking to tell it what to do on the javascript "onmousedown" event, then you will need to a)watch your case sensitivity, and b)attach it as an attribute to the element. i.e., shop.setAttribute("onmousedown", "alert('PENIXEN!')");

Name: Anonymous 2009-05-02 3:12

what the fuck?
first, lets transform your code into something that actually makes sense.
this uses mootools.



window.addEvent('domReady', function(){
    var x = 0;
    var y = 0;
   
    $('shop').addEvents({
        'mousedown':function(e){
            this.set('src', 'buttons/shop3.png');
        },
        'mouseup':function(e){
            this.set('src', 'buttons/shop4.png');
            x=1;
            y=1;
        },
        'mouseout':function(e){
            var src = (x==2) ? 'buttons/shop4.png' : 'buttons/shop1.png';
            this.set('src', src);
        },
        'mouseover':function(e){
            var src = (x==2) ? 'buttons/shop3.png' : 'buttons/shop2.png';
            this.set('src', src);
        }
    });   
});


now look. what's going on with that x and y? it's never ever going to be 2.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List