otherbasic5.js
// JavaScript: Other Basic Techniques, Example 5
// Function changes image when it is clicked and a confirm message is accepted
//
// Copyright (c) Paul Griffiths, 2007
// Email: mail@paulgriffiths.net
var newsrc = "mars.jpg";
function changeImage() {
if ( newsrc == "mars.jpg" && confirm("Are you sure you want to change the image to Mars?") ) {
document.images["pic"].src = "/images/program/js/forms/mars.jpg";
document.images["pic"].alt = "Mars";
newsrc = "earth.jpg";
}
else if ( newsrc == "earth.jpg" && confirm("Are you sure you want to change the image to Earth?") ) {
document.images["pic"].src = "/images/program/js/forms/earth.jpg";
document.images["pic"].alt = "Earth";
newsrc = "mars.jpg";
}
}