views:

66

answers:

3

Why does this not work ? In Firebug, when I click on the button, it always says to me that cambiaBandiera is not defined ...

HELP

Alex

CSS

#ITA{
float:right;
margin : 5px 85px;
width:40px;
height:40px;
background : #FFFFFF url("../ITA_off.png") center center no-repeat;
border:0;
}

JAVASCRIPT (in HEAD)

<style type="text/javascript">
function cambiaBandiera() {
test=document.getElementById("ITA");
test.style.backgroundImage="url('../ITA_on.png')";
}
</style>

and this is HTML

<div id="bandiere">
<input type="button" id="ITA" onClick="cambiaBandiera()">  </input> 
</div>
A: 

Use plain CSS:

#bandiere:active{
    background : #FFFFFF url("../ITA_on.png") center center no-repeat;
}
erenon
What do you mean ?
Alpan67
Alpan67: use the CSS :active pseudo class to change the background of an element if you click on it. This technique is js-safe as well
erenon
In bandiere I will add more than ITA, that's why I created the ITA div
Alpan67
+1  A: 

You are specifying input in wrongly, adding not needed </input>:

<input type="button" id="ITA" onClick="cambiaBandiera()"></input> 

It should be:

<input type="button" id="ITA" onClick="cambiaBandiera()" />

input tag is self closing, it does not need closing tag.

Sarfraz
@Sarfraz Ahmed : yes you are right but it does not change, I tried also with your tip
Alpan67
+4  A: 

I see that you put your script between style tags instead of script tags. Maybe that is the reason it cannot find your function?

Peter Tillemans
@ Peter Tilemans : Sry, I don't understand, what do you mean ?
Alpan67
OK WHAT A MESS !!!!!!!!!!! Thank you Peter !
Alpan67