Why isn’t this working in Chrome?
HTML:
<div class="deo" id="a1">
<form id="formaA1" name="formaA1">
KOLIKO JE 3-1+5? //It`s simple equation, it says: How much is 3-1+5?
<br/>
<input type="text" id="pitanjeA1" name="pitanjeA1" />
<br/>
<button onClick="return a1();">Odgovor</button>
</form>
</div>
CSS:
.deo {
width: 24%;
height: 30%;
background-color: #808080;
float: left;
text-align: center;
}
img {
width: 100%;
height: 100%;
margin: auto;
}
JavaScript:
function a1() {
if (parseInt(document.formaA1.pitanjeA1.value) == 7) {
document.getElementById("a1").innerHTML = "<img src='zmaj_01.jpg'>";
return true;
} else {
alert("Netacan odgovor. \nPokusajte ponovo.");
return false;
}
}
It`s a simple program, everytime child answers correct piece of image appears.
It works fine in FireFox and IE, but in Chrome it does nothing.
Also, any critics on code is appreciated.
Thanks.
Use
.addEventListenerto attach your event, andevent.preventDefault();to prevent the form from actually submitting when the user clicks on the button.Also, when commenting HTML code, use the html comment syntax “
<!-- -->” instead of “//“Html:
Js:
Live Demo | Source