Forum Moderators: open
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Lesson 2 script</title>
<style type="text/css">
#image_style{float:right;}
</style>
<script type="text/javascript">
<!--
var name = prompt("Enter your name"," ");
var name_empty = "Welcome to this page <strong> friend<\/strong>";
//-->
</script>
<script type="text/javascript">
<!--
var temp="";
var picture1 = 'test1.jpg';
var picture2 = 'test2.jpg';
var picture3 = 'test3.jpg';
//-->
</script>
</head>
<body>
<p>
<img src="test1.jpg" alt="" id="image_style">
</p>
<h1>Browser configuration</h1>
<script type="text/javascript">
<!--
if(name==" ")
{
document.write(name_empty +"<br>");
}
else
{
document.write("Welcome to this page "+ name.bold() + "." + "<br>");
}
//-->
</script>
<p>Hover on the images, click to choose it and to change your browser image:<br><br></p>
<p><a href="#" onMouseOver="temp=picture1; picture1=picture2; picture2=picture3; picture3=temp; document.to_swap.src = picture1;" onClick="document.image_style.src=picture1;">
<img src="test1.jpg" alt=" " id="to_swap">
</a>
</p>
<script type="text/javascript">
<!--
//-->
</script>
</body>
</html> <p><a href="#" onMouseOver="temp=picture1; picture1=picture2; picture2=picture3; picture3=temp; document.to_swap.src = picture1;" onClick="document.image_style.src=picture1;">
<img src="test1.jpg" alt=" " id="to_swap">
</a> document.to_swap.src = picture1;"is supposed to copy what's in "picture1" in the picture with id "to_swap". <a href="#" onMouseOver="temp=picture1; picture1=picture2; picture2=picture3; picture3=temp;... in am not sure what's in "picture1" anymore. document.to_swap.src = picture1; taking in turn all the images? SOrry it is probably a really duff question...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Lesson 2 script</title>
<style type="text/css">
#image_style,#swap_anchor,#to_swap { display:block; width: 100px; height:100px; }
#image_style { float: right; }
</style>
<script type="text/javascript">
//
window.onload=function() { initialize(); }
//
function initialize () {
current_image=0;
img_array=['test1.jpg','test2.jpg','test3.jpg'];
var n = prompt("Enter your name","");
var name_empty = "friend";
var msg = "welcome to this page <strong>";
msg += (n=='')?name_empty:n;
msg += ".</strong>";
document.getElementById('welcome').innerHTML = msg;
var target_image = document.getElementById('to_swap');
var target_anchor=document.getElementById('swap_anchor');
target_image.onmouseover=function() { preview(target_image); }
target_anchor.onclick=function() { return swap_img(target_image.src); }
}
//
function preview(img_object) {
current_image=(current_image>=img_array.length-1)?0:current_image+1;
img_object.src=img_array[current_image];
}
//
function swap_img(img_src) {
document.getElementById('target-image').src=img_src;
return false;
}
</script>
<body>
<p id="image_style"><img id="target-image" src="test1.jpg" alt=""></p>
<p id="welcome"></p>
<p>Hover on the images, click to choose it and to change your browser image:<br><br></p>
<p><a href="#" id="swap_anchor"><img src="test1.jpg" alt=" " id="to_swap"></a></p>
</body>
</html>