Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

java click counter in html

hi

i have a site with several links on it and each link has a box next to it. the box is white to start with. on roll over it changes to red and when the link is clicked i want the box to turn blue but retain the red roll over feature.

i have got so far with the code;

<html>
<head>
<title>java test</title>
<script language="JavaScript" type="text/JavaScript">
<!--
var news = 0

if (document.images)
{
newson=new Image();
newson.src="red.gif";
if (news == 0){
newsoff=new Image();
newsoff.src="white.gif";
}
else{
newsoff=new Image();
newsoff.src="blue.gif";
}
}

function imgon(imgName){if (document.images){document[imgName].src=eval(imgName+"on.src");}}
function imgoff(imgName){if (document.images){document[imgName].src=eval(imgName+"off.src");}}
//-->
</script>

</head>
<body>
<a href="#" onMouseOver="imgon('news')" onMouseOut="imgoff('news')"><img
border="0" src="white.gif" name="news"> link</a>
</body>
</html>

so i need to change the variable 'news' to 1 when the link is clicked.

if you can tell me how to this, that would be great.

if you know a better way of achieving the same result please let me know.

also i was thinking of putting the java script in an external file like a style sheet. does any one have any experience doing this? will it mean that my rollover images are less likly to work?

cheers for any help

steve
[1660 byte] By [steveo] at [2007-11-11 8:03:56]
# 1 Re: java click counter in html
Hi Steve

I'm having a look at your code and will come back to you shortly. my developer has done this stuff.

sonia
web design uk ( http://www.xelonline.com)
web design manchester ( http://www.webdesign-manchester.com)
princess275 at 2007-11-11 22:36:36 >
# 2 Re: java click counter in html
You should be able to do this completely with CSS (if I'm understanding what you want to do). Something like:

a:after { width: 10px; height: 10px; content:' '; background-color: white; }
a:hover:after { background-color: red; }
a:active:after { background-color: blue; }

You will likely have to fiddle a bit with this to get everything looking the way that you want it to. For some reason, Firefox won't show empty strings in the elements, so you might need to put some small character and then just make the foreground and background color the same.

Hope this helps.
evlich at 2007-11-11 22:37:36 >