Graphic Swapping with an Image and 3 buttons in javascript

PROGRAM:

<html>
<head>
<script type="text/javascript">
function show(myname) {
        var iname;
        if (myname == "img4") {
                iname = "img4.jpg";
        } else {
                iname = eval(myname + ".src");
        }
        img4.src = iname;
}    
</script>
<title></title>
</head>
<body>
<br>
<br>
<br>
<table border="5px">
<tr>
<td><img src="img4.jpg" height=
"242" width="242" name="img4" id="img4"></td>
<td><input type="button" value="normal" onclick=
"show('img4')"></td>
</tr>
<tr>
<td><input type="button" value="BLUE" onclick="show('img1')"></td>
<td><input type="button" value="GREEN" onclick="show('img2')"></td>
<td><input type="button" value="RED" onclick="show('img3')"></td>
</tr>
<tr>
<td><img src="img1.jpg" alt="Smiley face"
height="242" width="242" name="img1" id="img1"></td>
<td><img src="img2.jpg" alt="Smiley face"
height="242" width="242" name="img2" id="img2"></td>
<td><img src="img4.jpg" alt="Smiley face"
height="242" width="242" name="img3" id="img3"></td>
</tr>
</table>
</body>
</html>

output:

Smiley face Smiley face Smiley face

No comments:

Post a Comment